CSS grid wrapping

前端 未结 5 909
借酒劲吻你
借酒劲吻你 2020-12-04 04:53

Is it possible to make a CSS grid wrap without using media queries?

In my case, I have a non-deterministic number of items that I want placed in a grid and I want th

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 05:55

    You may be looking for auto-fill:

    grid-template-columns: repeat(auto-fill, 186px);
    

    Demo: http://codepen.io/alanbuchanan/pen/wJRMox

    To use up the available space more efficiently, you could use minmax, and pass in auto as the second argument:

    grid-template-columns: repeat(auto-fill, minmax(186px, auto));
    

    Demo: http://codepen.io/alanbuchanan/pen/jBXWLR

    If you don't want the empty columns, you could use auto-fit instead of auto-fill.

提交回复
热议问题