How to set auto-margin boxes in flexible-width design using CSS?

后端 未结 8 1712
一整个雨季
一整个雨季 2020-12-11 02:04

I have DIV with flexible width set e.g. min-width:800px and max-width:1400px. In this DIV, there are many boxes with fix width 200px and display:inline-block. So depending o

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-11 02:49

    You need to make .box inline-blocks, and justify text in .wrapper. .wraper:after is needed to justify the last line. Older IEs don't understand after, but in IE text-align-last:center will take care of the last line.

    .wrapper{
        text-align:justify;
        max-width:1400px;
        min-width:800px;
        text-align-last:center;
    }
    .wrapper:after{
        content:'';
        display:inline-block;
        width:100%;
        height:0;
        font-size:0;
        line-height:0;
    }
    .box{
        display:inline-block;
        *display:inline;
        vertical-align:top;
        width:200px;
        height:50px;
        background:red;
    }
    

    Here's a jsfiddle.

提交回复
热议问题