圣杯布局的实现之浮动flaot

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

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>圣杯布局</title>
    <style>
        * {
     
     
            margin: 0;
            padding: 0;
        }
        
        header,footer {
     
     
            height: 100px;
            background-color: pink;
        }

        footer {
     
     
            clear: both;
        }

        .container {
     
     
            height: 100%;
            padding-left: 150px;
            padding-right: 100px;
        }

        .container div {
     
     
            position: relative; //container所有的div都设置为relative
            float: left;
            height: 500px;
        }

        .left {
     
     
            left: -150px;
            width: 150px;
            margin-left: -100%;
            background-color: rgb(206, 165, 243);
        }

        .right {
     
     
            right: -100px;
            width: 100px;
            margin-left: -100px;
            background-color: rgb(220, 194, 243);
        }

        .center {
     
     
            width: 100%;
            background-color: rgb(213, 182, 228);
        }
    </style>
</head>

<body>
    <header>header</header>
    <div class="container">
        <div class="center">center</div> /* center必须放在最前面*/
        <div class="left">left</div>
        <div class="right">right</div>
    </div>
    <footer>footer</footer>
</body>

</html>

效果图
圣杯布局

猜你喜欢

转载自blog.csdn.net/qq_41612593/article/details/116206469
今日推荐