css常见布局

1.普通布局(头部、内容、底部)

    <div class="container">
        <header></header>
        <div class="content"></div>
        <footer></footer>
    </div> 

2,两栏布局

左边固定大小,右边自适应

flex布局

.p{
     display: flex;
     
 }
 .p>div{
     height: 100px;
 }
 .a{
     background-color: pink;
     width: 200px;
 }
 .b{
     background-color: bisque;
flex: 1;
 }

浮动

 .p>div{
     height: 100px;
 }
 .a{
     background-color: pink;
     width: 200px;
     float: left;
 }
 .b{
     background-color: bisque;
    margin-left: 200px;
 }

第二种

.p>div{
     height: 100px;
 }
 .a{
     background-color: pink;
     width: 200px;
     float: left;
 }
 .b{
     background-color: bisque;
    width: 100%
    float: left;
 }

网格布局

 .container {
            display: grid;
            width: 100%;
            grid-template-rows: 300px;//每行的高
            grid-template-columns: 100px auto//每个元素的宽度
        }

3,三栏布局

flex实现

 .p{
     display: flex;
     
 }
 .p>div{
     height: 100px;
 }
 .a{
     background-color: pink;
     width: 200px;

 }
 .b{
     background-color: bisque;
     flex: 1;

 }
.c{
      background-color: pink;
      width: 200px;
 }

浮动实现

 .p{
     
 }
 .p>div{
     height: 100px;

 }
 .a{
     background-color: pink;
     width: 200px;
    float: left;
 }
 .b{
     background-color: bisque;
     /* margin-right: 200px; */
     /* float: left;
      */
     margin: 0 200px;
 }
.c{
      background-color: yellow;
      width: 200px;
     float: right;
 }

定位实现

父元素设置相对定位,左右元素分别设置left、right为0,然后中间元素的left分别为左右的width即可

.container {
            position: relative;
        }
        .left {
            position: absolute;
            left: 0;
            width: 100px;
            height: 300px;
            background-color: #ce5a4b;
        }
        .main {
            position: absolute;
            left: 100px;
            right: 200px;
            height: 300px;
            background-color: #f8cf5f;
        }
        .right {
            position: absolute;
            right: 0;
            width: 200px;
            height: 300px;
            background-color: #499e56;
        }

网格布局

 .container {
            display: grid;
            width: 100%;
            grid-template-rows: 300px;//每行的高
            grid-template-columns: 100px auto 200px;//每个元素的宽度
        }
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大鸡腿最好吃

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值