Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mx-auto not moving element to centre

Tags:

bootstrap-4

In following code, the text hello world is not moving to centre of the screen using mx-auto. What is the problem?

<div class="container-fluid">
        <div class="row "> 
            <div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 my-border" >
                <div class="alert alert-success mx-auto" >
                    Hello World
                </div>
            </div>
        </div> 
    </div>       
like image 786
Manu Chadha Avatar asked Nov 22 '17 05:11

Manu Chadha


1 Answers

mx-auto works with divs that have fix width , see below alert class :

.alert {
   padding: $alert-padding-y $alert-padding-x;
   margin-bottom: $alert-margin-bottom;
   border: $alert-border-width solid transparent;
   @include border-radius($alert-border-radius);
 }

and mx-auto class :

.mx-auto {
 margin-right: auto !important;
 margin-left: auto !important;
}

use text-center class instead

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<div class="container-fluid">
        <div class="row "> 
            <div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 my-border" >
                <div class="alert alert-success text-center" >
                    Hello World
                </div>
            </div>
        </div> 
    </div>      
like image 193
pritesh agrawal Avatar answered Oct 31 '22 01:10

pritesh agrawal