简体   繁体   中英

FLEXBOX min-width: min-content / max-width

I need this:

Container width fixed width, items flowing in the row direction and wrapping at the end.

each item should be max-width: 400px , overflowing content should be cut. the minimum width of the items should be determined by the content, however: it should never be shorter than 200px.

Here is my CSS code, it does not cover the "min-content" aspect. min-content is suggested by the w3 in their flexbox working draft, but it does not seem to work in my case:

.container {
    display: -webkit-flex;
    display: flex;
    -webkit-flex-wrap: wrap;
    flex-wrap: wrap;
}

.container .box {
    -webkit-flex: 1;
    flex: 1;
    min-width: 200px;
    max-width: 400px;
    height: 200px;
    background-color: #fafa00;
    overflow: hidden;
}

and the html is:

<div class="container">
    <div class="box">
        <table>
            <tr>
                <td>Content</td>
                <td>Content</td>
                <td>Content</td>
            </tr>
        </table>    
    </div>
    <div class="box">
        <table>
            <tr>
                <td>Content</td>
            </tr>
        </table>    
    </div>
    <div class="box">
        <table>
            <tr>
                <td>Content</td>
                <td>Content</td>
            </tr>
        </table>    
    </div>
    [...]
</div>

The problem is that flex: 1 sets flex-basis: 0 . Instead, you need

.container .box {
  min-width: 200px;
  max-width: 400px;
  flex-basis: auto; /* default value */
  flex-grow: 1;
}

 .container { display: -webkit-flex; display: flex; -webkit-flex-wrap: wrap; flex-wrap: wrap; } .container .box { -webkit-flex-grow: 1; flex-grow: 1; min-width: 100px; max-width: 400px; height: 200px; background-color: #fafa00; overflow: hidden; } 
 <div class="container"> <div class="box"> <table> <tr> <td>Content</td> <td>Content</td> <td>Content</td> </tr> </table> </div> <div class="box"> <table> <tr> <td>Content</td> </tr> </table> </div> <div class="box"> <table> <tr> <td>Content</td> <td>Content</td> </tr> </table> </div> </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM