CSS基本布局

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_39956624/article/details/82846434

左列定宽,右列自适应

利用float+margin实现

.left{float:left;width:100px;} 
.right{margin-left:100px;}

使用float+overflow实现

.left{width:100px;float:left;}
.right{overflow:hidden;}

实用flex实现

.parent{display:flex;}
.left{width:100px;}
.right{flex:1;}

经典圣杯布局

 <!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>圣杯布局</title>
    <style type="text/css">
        *{
            margin: 0;padding: 0;}
        body{
            min-width: 700px;}
        h3{
            padding:0 20px}
    .header{
        width: 100%;
        height: 40px;
        background-color: #646464;
    }
    .footer{
        width: 100%;
        height: 40px;
        margin-top: 300px;
        background-color: #646464;

    }
    .middle{
        float: left;
        width: 100%;
        height: 300px;
        text-align: center;
        background-color: #ffd36a;
    }
     .left{
        float:left;
        width: 200px;
        height: 300px;
        margin-left: -100%;
        background-color: #ff63bd;
        }
     .right{
         float: left;
         width: 200px;
         height: 300px;
         margin-left: -200px;
         background-color: #a2ff95;
        }
    </style>
</head>
<body>
<div class="header">
    <h3>header</h3>
</div>
<div class="middle">
    <h3>middle</h3>
</div>
<div class="left">
    <h3>left</h3>
</div>
<div class="right">
    <h3>right</h3>
</div>
<div class="footer">
    <h3>footer</h3>
</div>
</body>
</html>

两侧定宽,中栏自适应

利用float+margin实现

.left{width:100px;float:left;}
.center{float:left;width:100%;margin-right:-200px;}
.right{width:100px;float:right;}

利用flex实现

.parent{display:flex;}
.left{width:100px;}
.center{flex:1;}
.right{width:100px;}

猜你喜欢

转载自blog.csdn.net/qq_39956624/article/details/82846434