两边固定,中间自适应布局

1.浮动,先左右再中

.left{
    float: left;
    width: 300px;
    height: 100px;
    background: #000;
}
 .right{
     width: 300px;
     height: 100px;
     float: right;
     background: pink;
 }
 .main{
     height: 100px;
     background: blue;
 }


<div class="contain">
    <div class="left"></div>
    <div class="right"></div>
    <div class="main"><h1>aa</h1></div>
</div>

2.绝对定位

  .left{
            position:absolute;
            width: 300px;
            height: 100px;
            background: #000;
            left: 0;
        }

        .right{
            position: absolute;
            width: 300px;
            height: 100px;
            background: pink;
            right: 0;
        }
        .main{
            position: absolute;
            left: 300px;
            right: 300px;
            height: 100px;
            background: blue;
        }


    </style>
</head>
<body>
<div class="contain">
    <div class="left"></div>
    <div class="main">aa</div>
    <div class="right"></div>
</div>

3.弹性布局 flex 左中右

  .contain{
            display: flex;
            flex-flow: wrap row;
        }
       .left{
           width: 300px;
           height: 100px;
           background: #000;
       }

        .right{
            width: 300px;
            height: 100px;
            background: pink;
        }
        .main{
            flex: 1;
            height: 100px;
            background: blue;
        }


    </style>
</head>
<body>
<div class="contain">
    <div class="left"></div>
    <div class="main"></div>
    <div class="right"></div>
</div>

4.表格 布局

 .contain{
            width: 100%;
            display: table;
            height: 100px;
        }
        .contain div{
            display: table-cell;
        }
        .left{
            width: 300px;
            height: 100px;
            background: #000;
        }

        .right{
            width: 300px;
            height: 100px;
            background: pink;
        }
        .main{
            height: 100px;
            background: blue;
        }
        
    </style>
</head>
<body>
<div class="contain">
    <div class="left"></div>
    <div class="main">aa</div>
    <div class="right"></div>
</div>

5.网格布局

 .contain{
            display: grid;
            grid-template-columns: 300px auto 300px;
            grid-template-rows: 100px;
        }
        .left{
            background: #000;
        }
        .main{
            background: blue;
        }
        .right{
            background: pink;
        }
        
    </style>
</head>
<body>
<div class="contain">
    <div class="left">11111111</div>
    <div class="main">aa</div>
    <div class="right">44444444444444444</div>
</div>
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值