Home > DeveloperSection > Forums > How to set div horizontal center?
jayprakash sharma
jayprakash sharma

Total Post:117

Points:821
Posted on    March-11-2013 1:59 AM

 CSS-CSS3 CSS-CSS3 
Ratings:


 1 Reply(s)
 1110  View(s)
Rate this:

Hi Expert!

I have a div within another div. I want to set inner div in horizontal center, but I do not used margin and padding as px, because there is irritating for

setting px as hardcoded.

my code as par following!

<div style="background-color:#E5E5E5:height:150px;">

<div style="background-color:#E2E2E2; width:800px; height:100px;"></div>

</div>

Thanks in advance!



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    March-11-2013 8:39 AM

Hi Jayprakash!

use margin of div auto as following

<div style="background-color:#E5E5E5;height:150px;">
<div style="background-color:#C2C2C2; width:800px; height:100px;margin-left: auto; margin-right:auto;"></div>
</div>

Don't want to miss updates? Please click the below button!

Follow MindStick