流体网格问题

时间:2011-08-17 20:22:37

标签: css fluid-layout

我的第一个流体网格布局有问题。 在大多数浏览器中,此布局看起来有所不同(宽度不一)。它只适用于firefox。(不是例如chrome或opera) 我不明白为什么。

由于

<!DOCTYPE html>
<html>
  <head>
    <title>Grid Test</title>
    <style type="text/css">
      .col {
        float:left;
        background-color: grey;
        margin-left: 1%;
        margin-right: 1%;
        margin-top: 1px;
        margin-bottom: 1px;
        height: 50px;
        text-align: center;
      }

      .one_quater {
        width: 23%;
      }
      .two_quater {
        width: 48%;
      }
      .three_quater {
        width: 73%;
      }

      .one_thirds {
        width: 31.333%;
      }
      .two_thirds {
        width: 64.666%;
      }

      .one_half{
        width: 48%;
      }

      .one_full{
        width: 98%;
      }

      .clear {
        clear: both;
        display: block;
        overflow: hidden;
        visibility: hidden;
        width: 0;
        height: 0;
      }
    </style>
  </head>
  <body>
    <div class="row">
      <div class="col one_full">
        1/1
      </div>
    </div>
    <div class="clear"></div>

    <div class="row">
      <div class="col one_thirds">
        1/3
      </div>
      <div class="col one_thirds">
        1/3
      </div>
      <div class="col one_thirds">
        1/3
      </div>
      <div class="clear"></div>
    </div>


    <div class="row">
      <div class="col two_thirds">
        2/3
      </div>
      <div class="col one_thirds">
        1/3
      </div>
      <div class="clear"></div>
    </div>


    <div class="row">
      <div class="col one_thirds">
        1/3
      </div>
      <div class="col two_thirds">
        2/3
      </div>
      <div class="clear"></div>
    </div>


    <div class="row">
      <div class="col one_half">
        1/2
      </div>
      <div class="col one_half">
        1/2
      </div>
      <div class="clear"></div>
    </div>

    <div class="row">
      <div class="col one_quater">
        1/4
      </div>
      <div class="col one_quater">
        1/4
      </div>
      <div class="col one_quater">
        1/4
      </div>
      <div class="col one_quater">
        1/4
      </div>
      <div class="clear"></div>
    </div>

    <div class="row">
      <div class="col two_quater">
        2/4
      </div>
      <div class="col one_quater">
        1/4
      </div>
      <div class="col one_quater">
        1/4
      </div>
      <div class="clear"></div>
    </div>


    <div class="row">
      <div class="col one_quater">
        1/4
      </div>
      <div class="col two_quater">
        2/4
      </div>
      <div class="col one_quater">
        1/4
      </div>
      <div class="clear"></div>
    </div>

    <div class="row">
      <div class="col one_quater">
        1/4
      </div>
      <div class="col one_quater">
        1/4
      </div>
      <div class="col one_quater">
        1/4
      </div>
      <div class="col one_quater">
        1/4
      </div>
      <div class="clear"></div>
    </div>


    <div class="row">
      <div class="col one_quater">
        1/4
      </div>
      <div class="col three_quater">
        3/4
      </div>
      <div class="clear"></div>
    </div>

  </body>
</html>

1 个答案:

答案 0 :(得分:0)

你走在正确的轨道上。渲染不同的原因与pixel rounding有关,这对所有浏览器都是一个问题,尤其是IE。

查看this fiddle以查看兼容性建议