How to center a wrapper-div and not the content

别等时光非礼了梦想. 提交于 2019-12-03 13:34:02

问题


I want my page to always be centered in the browser without affecting the content( like align-text: center; does). I want to center my wrapper-div.. How do I do this?

Simplifed existing page:

<div id="wrapper">       
    <div id="header">
        Music Heaven
    </div>
    <div id="topmeny">             
    </div>
    <div id="menu">        
    </div>        
    <div id="content">                  
    </div>           
    <div id="bottom">
        SiteAdmin
    </div>
</div>

Entire fiddle: http://jsfiddle.net/EndQb/


回答1:


 #wrapper {
     width: ...
     margin: 0 auto;
 }

no need to set text-align




回答2:


Set your style something like for the wrapper div.

#wrapper {

width: 841px;
margin: 0 auto;

}

In this way the wrapper div will always be centered according to your screen width. I hope it helps.




回答3:


you can set the margin property for the wrapper div like following in CSS

#wrapper { margin:20px auto } 


来源:https://stackoverflow.com/questions/8701054/how-to-center-a-wrapper-div-and-not-the-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!