圣杯布局和双飞翼布局

泄露秘密 提交于 2020-01-06 19:51:44

圣杯布局

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .parent {
            overflow: hidden;
            padding: 0 100px;
        }

        .middle {
            float: left;
            height: 100px;
            width: 100%;
            background-color: green;
        }

        .left {
            /* 以便申明 left 属性 */
            position: relative;
            /* 移出当前界面,注意和 parent 中的 padding-left 配合正好 */
            left: -100px;
            float: left;
            height: 100px;
            width: 100px;
            background-color: red;
            /* 上移一行 */
            margin-left: -100%;
        }

        .right {
            position: relative;
            right: -100px;
            float: left;
            height: 100px;
            width: 100px;
            background-color: blue;
            /* 上移到上一行末尾 */
            margin-left: -100px;
        }
    </style>
</head>

<body>
    <div class="parent">
        <div class="middle">Middle</div>
        <div class="left">Left</div>
        <div class="right">Right</div>
    </div>
</body>

</html>

双飞翼布局

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
       .parent{
           overflow: hidden;
       }
       .middle{
           width: 100%;
           float: left;
       }
       .inner-middle{
           height: 100px;
           margin: 0 100px;
           background: steelblue;
       }
       .left{
           width: 100px;
           height: 100px;
           background: yellowgreen;
           float: left;
           margin-left: -100%;
       }
       .right{
           width: 100px;
           height: 100px;
           background: hotpink;
           float: left;
           margin-left: -100px;
       }
    </style>
</head>

<body>
    <div class="parent">
        <div class="middle">
            <div class="inner-middle">
                Middle
            </div>
        </div>
        <div class="left">Left</div>
        <div class="right">Right</div>
    </div>
</body>

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