3

Possible Duplicate: how-to-align-a-div-to-the-middle-of-the-page

I need to show this Div tag allways center of the page. but its not showing now its shwoing right hand side corner and center of the page some times. Allways I need to show this page at center.

Thanks

Community
  • 1
  • 1
Sandy
  • 105
  • 7
  • You don't have any height/width/top/left/bottom/right arguments to specify actual position – Marc B Jul 06 '11 at 15:12
  • If you are using Jquery go ahead use Jquery UI that could resolve your issue. – Anil Namde Jul 06 '11 at 15:12
  • http://stackoverflow.com/questions/210717/using-jquery-to-center-a-div-on-the-screen – Anil Namde Jul 06 '11 at 15:14
  • Possible duplicate of [How to align a
    to the middle (horizontally/width) of the page](https://stackoverflow.com/questions/953918/how-to-align-a-div-to-the-middle-horizontally-width-of-the-page)
    – Cœur Jul 12 '18 at 15:32

2 Answers2

2

You need to set a width to your div and add the margin css property shown below

 <div style="width:500px; margin:0 auto;">
     Your content
 </div>
Josh Mein
  • 28,107
  • 15
  • 76
  • 87
0

If you set width to 50%, then left position to 25% -> that way, your div will always be centered, no matter if you resize parent object.

#header {   
    width: 50%;
    left: 25%;
}

<div id='test' class='#header'>My content goes here</div>
FrenkyB
  • 6,625
  • 14
  • 67
  • 114