float圣杯布局

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>圣杯布局</title>
    <style type="text/css">
        body {
    
    
            min-width: 550px;
        }
        #header {
    
    
            text-align: center;
            background-color: #f1f1f1;
        }
		
		// 因为 center 是居中自适应的 所以要根据 left right 的值设置内边距
        #container {
    
    
            padding-left: 200px;
            padding-right: 150px;
        }
		// 中间内容全部需要浮动
        #container .column {
    
    
            float: left;
        }

        #center {
    
    
            background-color: #ccc;
            width: 100%;
        }
        #left {
    
    
            background-color: yellow;
            width: 200px;
            // 因为他是浮动的 所以 -100% 会让他与center 为同一行
            margin-left: -100%;
            position: relative;
            right: 200px;
        }
        #right {
    
    
            background-color: red;
            width: 150px;
            margin-right: -150px;
        }

        #footer {
    
    
            text-align: center;
            background-color: #f1f1f1;
        }

        /* 手写 clearfix */
        .clearfix:after {
    
    
            content: '';
            display: table;
            clear: both;
        }
    </style>
</head>
<body>
    <div id="header">this is header</div>
    <div id="container" class="clearfix">
        <div id="center" class="column">this is center</div>
        <div id="left" class="column">this is left</div>
        <div id="right" class="column">this is right</div>
    </div>
    <div id="footer">this is footer</div>
</body>
</html>

おすすめ

転載: blog.csdn.net/qq_52151772/article/details/121878608