圣杯布局和双飞翼布局

≡放荡痞女 提交于 2019-11-28 07:15:56

  圣杯布局及双飞翼布局主要用于解决左右两边盒子固定宽度。中间盒子宽度自适应的问题。

 

  圣杯布局:

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

  双飞翼布局:

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

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!