Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to break row ("clear" element) in css flexbox

Tags:

css

flexbox

Is it possible to "clear" element in a "display: flex" container?

I want to achieve something like this:

  • 20 elements in a row on a big screen
  • 10 elements in a row on a smaller screen
  • 5 elements in a row on a small screen

With floats, I could "clear" after each 5th element with proper media queries...

like image 745
Sqrcz Avatar asked Mar 26 '15 14:03

Sqrcz


People also ask

How do you break a row in Flex?

Using an element to break to a new flex row comes with an interesting effect: we can skip specifying the width of any item in our flex layout and rely completely on the line breaks to define the flow of our grid. This produces a layout with two vertically stacked full-width items (I've added a border to the .

How do I limit 3 items per row in Flexbox?

For 3 items per row, add on the flex items: flex-basis: 33.333333% You can also use the flex 's shorthand like the following: flex: 0 0 33.333333% => which also means flex-basis: 33.333333% .


1 Answers

You can add flex-wrap: wrap; to the container and set the width of the elements inside.

Then you should have the control to decide on which elements the floating will stop.

Demo: http://codepen.io/imohkay/pen/gpard

like image 186
paolo pieretto Avatar answered Oct 06 '22 12:10

paolo pieretto