【发布时间】:2010-10-27 07:26:02
【问题描述】:
我想将网页的文本和内容“居中”。现在我不想将文本对齐到中心,我仍然想要左对齐,但我想要左右两边的边距很大,这样所有东西看起来都相对居中。你能告诉我实现这一目标的 HTML/CSS 吗?谢谢。
【问题讨论】:
我想将网页的文本和内容“居中”。现在我不想将文本对齐到中心,我仍然想要左对齐,但我想要左右两边的边距很大,这样所有东西看起来都相对居中。你能告诉我实现这一目标的 HTML/CSS 吗?谢谢。
【问题讨论】:
<html>
<head>
<style type="text/css">
body {
text-align: center; /* Center in IE */
}
#content {
text-align: left; /* reset text-align for IE */
margin: 0 auto; /* Center in other browsers */
width: 800px;
}
html {
overflow: -moz-scrollbars-vertical; /* Force vertical scrollbar in FF */
}
</head>
<body>
<div id="content">
content here
</div>
</body>
</html>
*更新:我添加了一些 CSS,根据下面的一些 cmets 在 FF 中强制垂直滚动条。
【讨论】:
CSS:
#container {
max-width: 800px;
margin: 0 auto;
}
在 HTML 中,将所有内容包装在:
<div id='container'>
...
</div>
(请注意,这个答案与 meep 的不同之处在于,我使用 max-width 提供低于 800 像素的流畅布局,而他使用 width 提供固定布局。)
【讨论】:
有一个容器 div,您可以在其中放置所有内容:
<html>
<head>
<title>a sample</title>
</head>
<body>
<div id="container">
<h1>this is it</h1>
<p>all content goes here</p>
</div>
</body>
然后添加一些 css 指定容器 div 的宽度和边距:
#container {
width: 750px;
margin: 0 auto;
}
【讨论】:
试试
#div {
margin:0 auto
};
【讨论】:
在您的页面上创建 3 列。您的所有文本都位于中心列,并且可以左对齐。
在这里查看示例http://matthewjamestaylor.com/blog/perfect-3-column.htm
【讨论】:
我相信this 可能会对您有所帮助。
【讨论】:
#wrapper {
width: 800px;
margin: 0 auto;
}
<div id="wrapper">
<p>This will appear in a centered container</p>
</div>
【讨论】: