开发者

How to fix the position of the div tag at center of the page. using javascript

开发者 https://www.devze.com 2023-03-18 16:26 出处:网络
Po开发者_Python百科ssible 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

Po开发者_Python百科ssible 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


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>


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号