开发者

Trying to center my web page [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

page will not align center

I'm trying to center my web page using asp.net. When I use the <center> tag it only centers the content placeholder. 开发者_运维问答But when I use the CSS attribute margin: 0 auto, it doesn't do anything. Is there a way to center the whole page?


In your CSS:

body {
    text-align: center;
}

#container {
    width: 900px; /* or some other fixed-width value */
    margin: 0 auto;
    text-align: left; /* reset text-align */
}

Edit: guess I should probably show the associated markup as well...

...
<body>
    <div id="container">
        <!-- centered content here -->
    </div>
</body>
...


You need to have all your content with in a wrapping div, and have a set width on that element, along with margin: 0 auto;

Example:

#wrapper {
  width: 960px;
  margin: 0 auto;
}


You can use CSS:

  • http://davidwalsh.name/horizontally-center-website-structure-css
  • http://pmob.co.uk/pob/hoz-vert-center.htm
  • http://www.dynamicsitesolutions.com/css/center-page-content-horizontally-and-vertically/
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜