聖盃佈局和雙飛翼佈局

  聖盃佈局及雙飛翼佈局主要用於解決左右兩邊盒子固定寬度。中間盒子寬度自適應的問題。html

 

  聖盃佈局:佈局

<!doctype html>
<html>

<head>
    <title>聖盃佈局</title>
    <meta charset="utf-8">
    <style>
        body {
            min-width: 800px;
            margin: 0;
            padding: 0;
        }

        .container {
            padding: 0 300px 0 200px;
            overflow: hidden;
        }

        .header {
            width: 100%;
            height: 100px;
            background-color: lightblue;
        }

        .footer {
            width: 100%;
            height: 50px;
            background-color: lightblue;
        }
        .middle, .left, .right{
            position: relative;
        }
        .middle {
            float: left;
            width: 100%;
            height: 100px;
            text-align: center;
            background: lightcoral;
        }

        .left {
            float: left;
            width: 200px;
            margin-left: -100%;
            left:-200px; 
            height: 100px;
            background: lightgreen;
        }

        .right {
            float: left;
            width: 300px;
            height: 100px;
            margin-left: -300px;
            right: -300px;
            background: lightseagreen;
        }
    </style>
</head>

<body>
    <div class="header">header</div>
    <div class="container">
        <div class="middle">middle</div>
        <div class="left">left</div>
        <div class="right">right</div>
    </div>

    <div class="footer">footer</div>
</body>

</html>

  雙飛翼佈局:flex

<!doctype html>
<html>

<head>
    <title>聖盃佈局</title>
    <meta charset="utf-8">
    <style>
        body {
            min-width: 800px;
            margin: 0;
            padding: 0;
        }

        .container {
              width:100%;
              height:100px;
              background-color: red;
              float: left;
        }

        .header {
            width: 100%;
            height: 100px;
            background-color: lightblue;
        }

        .footer {
            width: 100%;
            height: 50px;
            clear: both;
            background-color: lightblue;
        }
        .middle {
            margin: 0 300px 0 200px;
        }

        .left {
            float: left;
            width: 200px;
            margin-left: -100%;
            height: 100px;
            background: lightgreen;
        }

        .right {
            float: left;
            width: 300px;
            height: 100px;
            margin-left: -300px;   
            background: lightseagreen;
        }
    </style>
</head>

<body>
    <div class="header">header</div>
    <div class="container">
        <div class="middle">middle <div>hahah</div></div>
    </div>
        <div class="left">left</div>
        <div class="right">right</div>
    <div class="footer">footer</div>
</body>

</html>

   另外用彈性盒模型能夠很容易的構造三列布局spa

<html>
    <head>
        <meta charset="utf-8">
        <style>
            body{
                margin: 0;
            }
            .container{
                display: flex;
                height: 100px;
            }
            .middle{
                width: 100%;
                background: lightblue;
            }
            .left,.right{
                background: lightcoral;
                width: 200px;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="left">left</div>
            <div class="middle">middle</div>
            <div class="right">right</div>
        </div>
    </body>
</html>
相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息