How to set div horizontal center?

Total Post:117

 1864  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>


Thanks in advance!

  1. Post:604

    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>

      Modified On Mar-29-2018 11:14:44 PM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.