【发布时间】:2014-01-07 14:58:24
【问题描述】:
问题:margin: 0 auto 在 body 上不起作用。另一方面,background-color: #EEEEEE 正在工作,即使它们位于同一块上。
index.php:
<html>
<head>
<title>MForte</title>
<link rel="stylesheet" type="text/css" href="css/reset.css">
<link rel="stylesheet" type="text/css" href="css/bodyStyleSheet.css">
</head>
<body id="container">
<p>test</p>
<p>test</p>
<p>test</p>
</body>
</html>
reset.css:
/**
* Eric Meyer's Reset CSS v2.0 (http://meyerweb.com/eric/tools/css/reset/)
* http://cssreset.com
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
bodyStyleSheet.css:
#container {
margin: 0 auto;
background-color: #EEEEEE;
}
我尝试过的:
1) 将<link rel="stylesheet" type="text/css" href="css/reset.css"> 和<link rel="stylesheet" type="text/css" href="css/bodyStyleSheet.css"> 相互交换。
2) 从index.php 文件中删除了body 的id,并将#container 替换为body
3) 为了测试场景,由于border: 0 是在reset.css 上声明的,我尝试在index.php 上创建一个包含2 行的table。 border: 1 在 reset.css 的 table 标记中声明。边框未显示。
【问题讨论】:
-
你没有做任何事情来阻止
body简单地占用整个允许的宽度,所以这就是margin: 0 auto;不会做任何事情的原因。先修复body的宽度,让它不像html那么宽,你会看到margin在做点什么。
标签: php html css stylesheet