CSS 3 Column float (2 fixed, 1 dynamic)

后端 未结 2 1832
傲寒
傲寒 2021-02-08 16:06

I\'m designing a header which is made of 3 parts.

The page must be fluid: min-width:940px; max-width:1200px;

The first two parts of the header will

相关标签:
2条回答
  • 2021-02-08 16:18

    Try this:

    <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>
    
    0 讨论(0)
  • 2021-02-08 16:21

    I don't have enough reputation to comment, but I just wanted to endorse the correctness of the previous answer. I was looking for something slightly different: fixed-liquid-fixed, so tweaked it as follows:

    <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>
    

    Key points to notice: - margins, with float, are used to prevent the body overlapping with the edges. - in my case, you need to reverse the order of the divs in the html - you actually don't need a div for the "middle". One site that does without is the quirksmode blog (it just sets margins directly on the "body" element): http://www.quirksmode.org/blog/archives/browsers/index.html

    0 讨论(0)
提交回复
热议问题