javascript - Is it possible for flex items to align tightly to the items above them? -


this is, in effect, pinterest layout. however, solutions found online wrapped in columns, means container inadvertently grows horizontally. not pinterest layout, , not work dynamically-loaded content.

what want have bunch of images of fixed width , asymmetrical height, laid out horizontally wrapping in new row when limits of fixed-width container met:

can flexbox this, or have resort js solution masonry?

flexbox "1-dimensional" layout system: can align items along horizontal or vertical lines.

a true grid system "2-dimensional": can align items along horizontal , vertical lines. in other words, cells can span across columns , rows, flexbox cannot do.

this why flexbox has limited capacity building grids. it's reason why w3c has developed css3 technology, grid layout (see below).


in flex container flex-flow: row wrap, flex items must wrap new rows.

this means a flex item cannot wrap under item in same row.

enter image description here

notice above how div #3 wraps below div #1, creating new row. cannot wrap beneath div #2.

as result, when items aren't tallest in row, white space remains, creating unsightly gaps.

enter image description here

enter image description here

image credit: jefree sujit


column wrap solution

if switch flex-flow: column wrap, flex items stack vertically , grid-like layout more attainable. however, column-direction container has 3 potential problems right off bat:

  1. it expands container horizontally, not vertically (like pinterest layout).
  2. it requires container have fixed height, items know wrap.
  3. as of writing, has deficiency in major browsers the container doesn't expand accommodate additional columns.

as result, column-direction container may not feasible in many cases.


other solutions


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -