【问题标题】:CSS 3 Column float (2 fixed, 1 dynamic)CSS 3列浮动(2个固定,1个动态)
【发布时间】:2013-01-29 07:26:11
【问题描述】:

我正在设计一个由 3 个部分组成的标题。

页面必须流畅:min-width:940px; max-width:1200px;

标题的前两部分将是固定大小的:

   left       middle        right
<---------><---------><----------------->
   134px      183px       (Fill the remaining space)

我希望根据页面大小更改正确的部分,我将粘贴到目前为止的内容,但我的问题是让它完全填补空白。

HTML:

<div class="main">

<div class="left"></div>
<div class="middle"></div>
<div class="right"></div>

CSS:

    .main{
        margin:auto;
        min-width:940px;
        max-width:1200px;
        background-color:#000;
    }

    .left{
    float: left;
    width: 134px;
    height: 191px;
    background-color:#0000ff;
    }
    .middle{
    float: left;
    width: 183px;
    height: 191px;
    background-color:#ffff00;
    }

    .right{
    float: left;
    width: 60%;
    height: 191px;
    background-color:#ff0000;
    }

【问题讨论】:

  • 填补页眉或页面其余部分的空白?

标签: html css layout


【解决方案1】:

试试这个:

<html>
<head>
<title>Three columns</title>
<style type="text/css">
div.main { background-color: #000; }
div.left { float: left; width: 134px; height: 191px; background-color:#0000ff; }
div.middle { float: left; width: 183px; height: 191px; background-color:#ffff00; }
div.right { height: 191px; background-color: #ff0000; margin-left: 317px; }
</style>
</head>
<body>
<div class="main">
<div class="left"></div>
<div class="middle"></div>
<div class="right"></div>
</div>
</body>
</html>

【讨论】:

    【解决方案2】:

    我没有足够的声誉来发表评论,但我只是想认可上一个答案的正确性。我正在寻找一些稍微不同的东西:固定液体固定,所以调整如下:

    <html>
    <head>
    <title>Three columns</title>
    <style type="text/css">
    div.main { background-color: #000; }
    div.left { float: left; width: 134px; height: 191px; background-color:#0000ff; }
    div.middle { height: 191px; background-color: #ff0000; margin-left: 134px; margin-right: 183px;}
    div.right { float: right; width: 183px; height: 191px; background-color:#ffff00; }
    </style>
    </head>
    <body>
    <div class="main">
    <div class="left"></div>
    <div class="right"></div>
    <div class="middle"></div>
    </div>
    </body>
    </html>
    

    需要注意的要点: - 带浮动的边距用于防止主体与边缘重叠。 - 就我而言,您需要颠倒 html 中 div 的顺序 - 实际上,“中间”不需要 div。一个不需要的网站是 quirksmode 博客(它只是直接在“body”元素上设置边距):http://www.quirksmode.org/blog/archives/browsers/index.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-29
      • 2012-09-03
      • 2016-12-29
      • 2012-12-15
      • 2015-12-23
      • 2023-03-23
      • 1970-01-01
      相关资源
      最近更新 更多