HOW TO SET DIV HORIZONTAL CENTER?

jayprakash sharma

Total Post:117

Points:821
Posted by  jayprakash sharma
 1463  View(s)
Ratings:
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!

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: How to set div horizontal center?

    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>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!