【问题标题】:Center liquid layout中心液体布局
【发布时间】:2012-03-26 01:12:34
【问题描述】:

我看不出问题出在哪里,但.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;
}
​

【问题讨论】:

    标签: html css center liquid-layout


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      如果你不想改变宽度,或者从 topbar 中删除浮动并添加 margin: 0 auto 。 http://jsfiddle.net/P4TpQ/4/

      【讨论】:

        【解决方案3】:
        .topbar {
           width: 100%;
           height: 50px;
           background: #000;
        }
        

        【讨论】:

          猜你喜欢
          • 2011-06-12
          • 2011-08-21
          • 1970-01-01
          • 1970-01-01
          • 2014-02-18
          • 1970-01-01
          • 2010-09-08
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多