My goal is to achieve the following layout:
On a Search Results
website, there are two containers.
Container 1
and Container 2
are both DIV
elements with the CSS property float: left
.
Inside Container 2
is an unordered list (UL
) with a dynamic number of list items (LI
).
https://i.sstatic.net/XYYzN.png
If there are matching search results, Container 1
should be visible. However, it may not always be present in the HTML structure.
In cases where Container 1
is absent, I want Container 2
to expand to full width with the list items floating left.
https://i.sstatic.net/Ox8Cg.png
If the viewport's width (in a responsive design) cannot accommodate both containers side by side, then Container 2
should move to a new row while still maintaining full width with the list items floated left.
https://i.sstatic.net/Kpn1S.png
Simply setting the list items to float: left
causes Container 2
to collapse into a new row. Attempting to use display: inline-block
for the list items also leads to container collapse.
Do you have any elegant solutions using CSS for this issue? I've tried various methods without success.
JSFiddle Example: https://jsfiddle.net/y8vctgun/1/