美文网首页
CSS:div平均分几块

CSS:div平均分几块

作者: 一名有马甲线的程序媛 | 来源:发表于2017-12-04 15:08 被阅读146次

html:

    <div class="container">
        <div class="childDiv"></div>
        <div class="childDiv"></div>
        <div class="childDiv"></div>
    </div>

css:
法一:浮动布局+百分比

        .container{
            overflow: hidden;
            zoom:1;
            width:500px;
            height:200px;
            border:1px solid red;
        }
        .childDiv{
            float:left;
            width:33.3%;
            height:100%;
            border:1px solid red;
            background:greenyellow;
        }

法二:行内元素+百分比

        .container{
            font-size: 0;
            overflow: hidden;
            width:500px;
            height:200px;
            border:1px solid lightblue;
        }
        .childDiv{
            display: inline-block;
            width: 33.3%;
            height:100%;
            border:1px solid gray;
        }

法三:父元素 display:table + 子元素 display:table-cell

        .container{
            width:500px;
            height:200px;
            display: table;
            border:1px solid lightblue;
        }
        .childDiv{
            display: table-cell;
            border:1px solid gray;
        }

法四:css3 display:flex

        .container{
            width:500px;
            height:200px;
            display: flex;
            border:1px solid lightblue;
        }
        .childDiv{
            flex:1;
            border:1px solid gray;
        }

相关文章

网友评论

      本文标题:CSS:div平均分几块

      本文链接:https://www.haomeiwen.com/subject/rmrxixtx.html