簡體   English   中英

CSS 3列浮動(2個固定,1個動態)

[英]CSS 3 Column float (2 fixed, 1 dynamic)

我正在設計一個由3個部分組成的標題。

頁面必須是流動的: min-width:940px; max-width:1200px; 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>
<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>

我沒有足夠的聲譽來發表評論,但我只想贊同前一個答案的正確性。 我正在尋找一些略有不同的東西:固定液體固定,所以調整如下:

<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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM