Trying to center my web page [duplicate]
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/
精彩评论