CSS side by side div's auto equal widths

前端 未结 5 1666
独厮守ぢ
独厮守ぢ 2020-11-28 23:30
5条回答
  •  伪装坚强ぢ
    2020-11-29 00:28

    For the sake of older browser compatibility, here's a solution that works.

    html:

    css:

    .parent{
        height: 200px;
        background: #f00;
    }
    .parent > div{
        width: calc(100%/3);
        height: 100%;
        float: left;
        background: #fff;
    }
    

    However, to make it dynamic, since you'd know if it'd be 2 or 3 columns, you can put the count in a variable and do internal / inline css:

    //$count = 2 or 3

    Internal CSS (recommended)

    ...
    
    
    ...
    

    Inline CSS:

提交回复
热议问题