-1

I am using a <div> container and set that container to 100%. Inside that container i have mentioned several <div> with 50% and it align to left side. Now my question is, whether can i center align the main container to align center. So that my inner container align to center. Please help me.

My html code is,

<div class="container">
     <div class="co1">
           <p>content</p>
     </div>
     <div class="co2">
           <p>content</p>
     </div>
</div>

My css code is,

.container{
width:100%;
}

.co1{
width:50%;
}

.co2{
width:50%;
}
user2644743
  • 215
  • 3
  • 9
  • 18

4 Answers4

1

Use margin CSS property to centralize the Div.

For instance

margin: 0 auto;

Nitesh
  • 15,425
  • 4
  • 48
  • 60
0
margin-left:0 auto;
margin-right:0 auto;
SaturnsEye
  • 6,297
  • 10
  • 46
  • 62
0

Yes, this is done with the auto margins which work horizontally only:

Add the following to your CSS for the 2 DIVs inside.

margin: 0 auto;
Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
0

You need to set margins to auto.

margin-left : auto;
margin-right : auto;
Rajdeep Singh
  • 17,621
  • 6
  • 53
  • 78