1

我看不出问题出在哪里,但.topbar没有像应有的那样居中……左右距离应该相等。

http://jsfiddle.net/P4TpQ/

这是我的代码:

<!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;
}
​
4

3 回答 3

1
.topbar {
   width: 100%;
   height: 50px;
   background: #000;
}
于 2012-03-26T03:56:50.270 回答
1

将 .topbar 的宽度设置为 100% 而不是继承。 http://jsfiddle.net/P4TpQ/2/

或从顶部栏删除浮动并添加 margin: 0 auto 如果您不希望更改宽度。 http://jsfiddle.net/P4TpQ/4/

于 2012-03-26T01:19:02.550 回答
1

您正在继承width:90%- 要么明确地将其设置为 100%,要么不浮动包装器后代:http: //jsfiddle.net/P4TpQ/3/

另外:浮动所有包装器后代很有可能在以后咬你。如果绝对需要,请尝试直接子选择器,例如.wrapper>*

于 2012-03-26T01:19:31.857 回答