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

后端 未结 8 1708
一整个雨季
一整个雨季 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:40

    This is as close as IE7-compatible CSS can get: http://jsfiddle.net/thirtydot/79mFr/

    If this still isn't right, it's time to look at using JavaScript and hopefully also jQuery. If you define your requirements properly, it should be trivial to get this perfect with JavaScript.

    HTML:

    ..

    CSS:

    #container {
        border: 2px dashed #444;
    
        text-align: justify;
        -ms-text-justify: distribute-all-lines;
        text-justify: distribute-all-lines;
    
        min-width: 800px;
        max-width: 1400px
    }
    
    #container > div {
        margin-top: 16px;
        border: 1px dashed #f0f;
        width: 200px;
        height: 200px;
        vertical-align: top;
        display: inline-block;
        *display: inline;
        zoom: 1
    }
    .stretch {
        width: 100%;
        display: inline-block;
        font-size: 0;
        line-height: 0
    }
    

    The extra span (.stretch) can be replaced with :after.

    This still works in all the same browsers as the above solution. :after doesn't work in IE6/7, but they're using distribute-all-lines anyway, so it doesn't matter.

    See: http://jsfiddle.net/thirtydot/79mFr/2/

    There's a minor downside to :after: to make the last row work perfectly in Safari, you have to be careful with the whitespace in the HTML.

    Specifically, this doesn't work:

    And this does:

提交回复
热议问题