双飞翼布局快速记忆

229 阅读1分钟

核心记忆点:

  • 左右盒子margin负值,中间父盒子宽度100%,中间子盒子自适应
 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .left {
            width: 200px;
            background: red;
            height: 500px;
            float: left;
            margin-left: -100%;
        }
        .right {
            width: 300px;
            background: blue;
            height: 500px;
            float: left;
            margin-left: -300px;
        }
        .content {
            float: left;
            width: 100%;
        }
        .box {
            background: green;
            height: 500px;
            margin-left: 200px;
            margin-right: 300px;
        }
    </style>
</head>
<body>
    
    <div class="wrap">
        <div class="content">
            <div class="box"></div>
        </div>
        <div class="left"></div>
        <div class="right"></div>
    </div>
</body>
</html>