LearnFast.Ninja

CSS center absolute div

Two examples to center absolute div with CSS.

Option 1:

<div class="centerAbsolute_a">

    <div class="centerAbsolute_b">

       
   
</div>
</
div>


.centerAbsolute_a

{

      position: absolute;
     
left: 50%;
}

.centerAbsolute_b

{

      position: relative;

      left: -50%;
}


Option 2:

<div class="centerAbsolute_a">

    <div class="centerAbsolute_b">

       
   
</div>
</
div>


.centerAbsolute_a

{
    
position: relative;
}

.centerAbsolute_b

{

    position: absolute;
   
left: 0;
   
right: 0;

    margin-left: auto;

    margin-right: auto;

}


Tags

css

absolute center div