圣杯布局

77 阅读1分钟

主要是利用浮动然后是margin和position:relative

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="box">
        <div class="center"></div>
        <div class="left"></div>
        <div class="right"></div>
    </div>
</body>

</html>
<style>
    .box {
        overflow: hidden;
        padding: 0 200px;
    }

    .center,
    .left,
    .right {
        float: left;
    }

    .left,
    .right {
        width: 200px;
        height: 200px;
    }

    .left {
        background: red;
        margin-left: -100%;
        position: relative;
        left: -200px;
    }

    .right {
        background: blue;
        margin-right: -200px;
    }

    .center {
        width: 100%;
        height: 400px;
        background: yellow;
    }
</style>