我看不出哪里有问题,但是.topbar
没有居中,因为它应该是......左右距离应该相等。
这是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>asd</title>
</head>
<body>
<div class="wrapper">
<div class="topbar">asd</div>
</div>
</body>
</html>
* {
margin:0;
padding:0;
}
body {
background:#000;
font:14px Arial, Helvetica, sans-serif;
background-color:#FFF;
background-repeat:repeat;
}
.wrapper {
width:90%;
min-widht:200px;
margin:0 auto;
}
.wrapper * {
float:left;
}
.topbar {
width:inherit;
height:50px;
background:#000;
}
答案 0 :(得分:1)
将.topbar的宽度设置为100%而不是继承。 http://jsfiddle.net/P4TpQ/2/
或从顶部栏中移除浮动并添加边距:如果您不想更改宽度,则自动添加0。 http://jsfiddle.net/P4TpQ/4/
答案 1 :(得分:1)
您继承width:90%
- 要么显式设置为100%,要么不要浮动包装后代:http://jsfiddle.net/P4TpQ/3/
另外:浮动所有包装后代有一个很好的潜力,可以在以后咬你。如果绝对需要,请尝试直接子选择器,如.wrapper>*
答案 2 :(得分:1)
.topbar {
width: 100%;
height: 50px;
background: #000;
}