实现三个div,固定左右两边的div宽为200,中间的div宽度自适应的四种方法

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>实现三个div,固定左右两边的div宽为200,中间的div宽度自适应的四种方法</title>
        <style type="text/css">
            html,
            body {
                width: 100%;
                height: 100%;
                margin: 0;
                padding: 0;
                color: #fff;
                text-align: center;
                line-height: 100px;
            }
            
            .clear:after {
                content: "";
                display: block;
                height: 0;
                clear: both;
            }
            /*float法*/
            
            .left {
                float: left;
                width: 200px;
                height: 100px;
                background: Red;
            }
            
            .right {
                float: right;
                width: 200px;
                height: 100px;
                background: green;
            }
            
            .center {
                margin-left: 200px;
                margin-right: 20px;
                height: 100px;
                background: blue;
            }
            /*position*/
            
            .position {
                position: relative;
                margin-bottom: 100px;
            }
            
            .left2 {
                position: absolute;
                left: 0;
                top: 0;
                width: 200px;
                height: 100px;
                background: Red;
            }
            
            .right2 {
                position: absolute;
                right: 0;
                top: 0;
                width: 200px;
                height: 100px;
                background: green;
            }
            
            .center2 {
                position: absolute;
                left: 200px;
                right: 200px;
                top: 0;
                background: blue;
            }
            /*table*/
            
            .table {
                display: table;
                width: 100%;
            }
            
            .table .child {
                display: table-cell;
            }
            
            .left3 {
                width: 200px;
                height: 100px;
                background: Red;
            }
            
            .right3 {
                width: 200px;
                height: 100px;
                background: green;
            }
            
            .center3 {
                height: 100px;
                background: blue;
            }
            /*flex*/
            
            .flex {
                display: box;
                display: -webkit-box;
                display: -moz-box;
            }
            
            .left4 {
                width: 200px;
                height: 100px;
                background: Red;
            }
            
            .right4 {
                width: 200px;
                height: 100px;
                background: green;
            }
            
            .center4 {
                box-flex: 1;
                -webkit-box-flex: 1;
                -moz-box-flex: 1;
                background: blue;
            }
        </style>
    </head>

    <body>
        <div class="clear">
            <div class="left">float法</div>
            <div class="right">float法</div>
            <div class="center">float法</div>
        </div>
        <br />
        <div class="position clear">
            <div class="left2">position法</div>
            <div class="right2">position法</div>
            <div class="center2">position法</div>
        </div>
        <br />
        <div class="table clear">
            <div class="left3 child">table法</div>
            <div class="center3 child">table法</div>
            <div class="right3 child">table法</div>
        </div>
        <br />
        <div class="flex clear">
            <div class="left4 child">flex法</div>
            <div class="center4 child">flex法</div>
            <div class="right4 child">flex法</div>
        </div>
    </body>

</html>

效果图

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

前端_小明

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

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

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

打赏作者

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

抵扣说明:

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

余额充值