圣杯布局和双飞翼布局

圣杯布局

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>圣杯布局</title>
    <style>
        body {
            min-width: 550px;
        }
        #header {
            text-align: center;
            background-color: pink;
        }
        #container {
            padding-left: 200px;
            padding-right: 150px;
        }
        #container .column {
            float: left;
            height: 300px;
        }
        #center {
            width: 100%;
            background-color: #ccc;
        }
        #left {
            position: relative;
            width: 200px;
            background-color: yellow;
            margin-left: -100%;
            right: 200px;
        }
        #right {
            width: 150px;
            background-color: red;
            margin-right: -150px;
        }
        #footer {
            clear: both;
            text-align: center;
            background-color: pink;
        }
    </style>
</head>
<body>
    <div id="header">头部</div>
    <div id="container">
        <duv id="center" class="column">中间 宽度自适应100%</duv>
        <div id="left" class="column">左边 200px</div>
        <div id="right" class="column">右边 150px</div>
    </div>
    <div id="footer">尾部</div>
</body>
</html>

效果:

 

双飞翼布局

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>双飞翼布局</title>
    <style>
        body {
             min-width: 550px;
        }
        .column {
            float: left;
        }
        #main {
            width: 100%;
            height: 200px;
            background-color: #ccc;
        }
        #center {
            margin-right: 190px;
            margin-left: 190px;
        }
        #left {
            width: 190px;
            height: 200px;
            background-color: #0000FF;
            margin-left: -100%;
        }
        #right {
            width: 190px;
            height: 200px;
            background-color: #FF0000;
            margin-left: -190px;
        }
    </style>
</head>
<body>
    <div id="main" class="column">
        <div id="center">中间 自适应100%</div>
    </div>
    <div id="left" class="column">左边 190px</div>
    <div id="right" class="column">右边 190px</div>
</body>
</html>

效果:

注意:因为main和left、right平级,所以我们需要在它们上面加上float: left;让三者在一行上浮动

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页