负边距实现圣杯布局

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

<head>
    <meta charset="UTF-8">

    <title>Document</title>
    <style type="text/css">
        .left,
        .middle,
        .right {
            position: relative;
            float: left;
            min-height: 400px;
        }

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

        .left {
            width: 200px;
            left: -200px;
            margin-left: -100%;
            background: yellow;
        }

        .right {
            width: 200px;
            right: -200px;
            margin-left: -200px;
            background: purple;
        }

        .middle {
            width: 100%;
            background: orange;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="middle">
            我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局我是圣杯布局
        </div>
        <div class="left">左左</div>
        <div class="right">右右</div>
    </div>
</body>

</html>

 

posted @ 2020-12-22 09:54  wujf  阅读(71)  评论(0编辑  收藏  举报