Within a fixed width container, I have multiple square <li>
elements organized in rows inside a ul
. Once these elements reach the edge of the container, they drop to a new row below (think of it as building a brick wall with these <li>
elements).
I am seeking a solution to anchor all of these elements to the top of the container so that they form only a single row positioned side by side. The challenge is that using position: absolute; top:0;
causes them to lose their horizontal alignment.
Is there a way to achieve this using Javascript, where the elements remain horizontally aligned while being pinned to the top of the container? It's acceptable for them to overlap and stack on top of each other in this scenario.