javascript - Layout divs in rows then columns -
i have container div , 3 div inside following.
<div> <div>1</div> <div>2</div> <div>3</div> </div> i don't know content of each div inside, have variable height , width.
height of container decided tallest div inside.
i want show these div such way fill height first (left right) , move next column below.
+------------------+ |+-------++-------+| || || || || || || |+-------+| || |+-------+| || || || || || || || |+-------+| || | +-------+| +------------------+ obviously if these divs big , can't fit in 1 column, layout 3 columns below
+---------------------------+ |+-------++-------++-------+| || || || || || || || || || || || || || || || || || |+-------+| || || | | || |+-------+ | || | +-------+| +---------------------------+ question: possible preferably using css , how?
edit:
- there few things need clarify
- the container can have 2 or 3 columns @ (never 1 column , never more 3).
- width of container not fixed of internal div same.
- height of container decided tallest internal div. example if tallest div 300px height of container 300px.
- the other 2 shorter div should decide if can fit in 1 column or should show in 2 separate columns. based on example (previous item).
- the other 2 smallest div should decide in 1 column or 2 columns.
- none of internal div should wrapped.
example: div heights: 1st 300px, 2nd 100px, 3rd 150px
result: 2 column layout (2nd , 3rd in same column).
example: div heights: 1st 100px, 2nd 300px, 3rd 150px
result: 3 column layout.
example: div heights: 1st 100px, 2nd 200px, 3rd 300px
result: 2 column layout (1st , 2nd in same column).
example: div heights: 1st 100px, 2nd 210px, 3rd 300px
result: 3 column layout.
an css only solution columns use column-count , max-height on container (the wrapping div).
see answer: css float under , left
and demo of css-only approach
it kinda want, @ least extend. might break divs @ column breaks. think, better of in javascript.
update:
after additional conditions, add answer, concerning css-only approach: column-break-inside:avoid. still ain't perfect - bit closer want. you have assign width columns, divs can set width:100%, number of columns automatic, alright, not sure if can dynamicaly adjust container's width number of columns.
another note: avoid splitting divs in firefox, need use display:inline-block; in addition.
so, here can see how performs examples: demo
at least play , maybe use time ;-)
Comments
Post a Comment