I have a container div
and 3 div
inside it, as shown below.
<div> <div>1</div> <div>2</div> <div>3</div> </div>
I do not know about the contents of each div
inside, but they have a variable height and width.
The height of the container is determined by the highest div
inside.
I want to show these div
so that they first fill the height (from left to right) and then move on to the next column, as shown below.
+------------------+ |+-------++-------+| || || || || || || |+-------+| || |+-------+| || || || || || || || |+-------+| || | +-------+| +------------------+
Obviously, if these div
all large and cannot fit in one column, the layout will have 3 columns, as shown below
+---------------------------+ |+-------++-------++-------+| || || || || || || || || || || || || || || || || || |+-------+| || || | | || |+-------+ | || | +-------+| +---------------------------+
Question: Is it possible to do this using CSS only and how?
EDIT :
- There are a few things I need to clarify.
- A container can contain no more than 2 or 3 columns (no more than 1 column and no more than 3).
- The width of the container is not fixed, but the same with all the inner divs.
- The height of the container is determined by the highest inner div. for example, if the highest div is 300px the height of the container, there will also be 300px.
- the other two shorter divs should decide whether they can fit in one column or should appear in two separate columns. based on an example (previous item).
- The remaining two smallest divs must be in the same column or two columns.
- none of the inner divs should be wrapped.
Example : div Heights: 1st 300px, 2nd 100px, 3rd 150px
Result: this is a two-line layout (second and third in the same column).
Example : div Heights: 1st 100px, 2nd 300px, 3rd 150px
Result: this is a 3-column layout.
Example : div Heights: 1st 100px, 2nd 200px, 3rd 300px
Result: this is a two-line layout (1st and 2nd in one column).
Example : div Heights: 1st 100px, 2nd 210px, 3rd 300px
Result: this is a 3-column layout.