Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set size and center alert box in twitter bootstrap

I'm trying to center and set the size to 80% of an alert box, however it's not working with the class text-center.

 <div class="text-center">

    <div class="alert alert-info" style="width: 80%;" role="alert"> <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> <strong>Hey!</strong>  It's just an alert... </div> 

</div>
like image 277
Vinny Avatar asked Jul 14 '16 16:07

Vinny


People also ask

How do I center an alert box in bootstrap?

Use center-block instead of text-center with alert if you want to center align the whole alert.

Which bootstrap 4 class can be used to create successful alert?

Bootstrap 4 provides an easy way to create predefined alert messages: × Success! This alert box indicates a successful or positive action.

How do you dismissible an alert?

To close the alert message, add a .alert-dismissible class to the alert container. Then add class="close" and data-dismiss="alert" to a link or a button element (when you click on this the alert box will disappear).


2 Answers

<div class="container-fluid">
    <div class="row">

        <div class="col-md-10 col-md-offset-1">
            <div class="alert alert-warning alert-dismissible fade in text-center" role="alert">
                <strong>Holy guacamole!</strong> Best check yo self, you're not looking too good.
            </div>
        </div>

  </div>
</div>

The class text-center functions as expected. Wrapping the .alert within the Bootstrap Grid also provides you the ability to restrict the total width of the notification.

Double-check that you don't have additional CSS that might be overriding your code. This was tested in Bootply: http://www.bootply.com/MFv1HMC0G7

like image 85
Robert Avatar answered Oct 25 '22 08:10

Robert


Use center-block instead of text-center with alert if you want to center align the whole alert.

<div class="alert alert-info center-block" style="width: 80%;" role="alert"> <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> <strong>Hey!</strong>  It's just an alert... </div> 

If you want to center align the text inside of alert use as:

<div class="alert alert-info" style="width: 80%;" role="alert">
    <p class="text-center">
     <i class="fa fa-exclamation-triangle" aria-hidden="true"></i>        <strong>Hey!</strong>  It's just an alert... 
    </p>
</div> 
like image 28
Lekhnath Avatar answered Oct 25 '22 06:10

Lekhnath