Control the number of items on each flex-line when container is set to wrap

前端 未结 2 1505
梦毁少年i
梦毁少年i 2021-01-21 22:03

I am using css flexbox to distribute a number of items in a container. I have a flex container like this:

.container{
    display: flex;
    flex-flow: row wrap;         


        
相关标签:
2条回答
  • 2021-01-21 22:33

    What you're looking for is sometimes referred to as Quantity Queries.

    If media queries allow for breakpoints based on viewport dimensions, quantity queries allow for breakpoints based on content quantity (e.g., sibling count).

    It's not part of any official standard but I wouldn't call it a hack. The code can be quite elegant. It is a bit involved, however. Here you go:

    • Quantity Queries for CSS
    • Styling elements based on sibling count
    • How to specify an element after which to wrap in css flexbox?
    0 讨论(0)
  • 2021-01-21 22:40

    Do you mean flex-basis?

    .container .item {
        flex-basis: 25%;
    }
    

    It will divide to maximum 4 item per row.

    0 讨论(0)
提交回复
热议问题