Issue
I am facing a challenge in aligning blocks to the left within a centered wrapper that has a dynamic width. Despite trying only HTML and CSS, I have been unsuccessful in achieving this.
To see an example of what I am dealing with, you can view this JSFiddle: https://jsfiddle.net/hudxtL8L/
Demonstration
My current layout resembles the following:
| _____ _____ |
| | | | | |
| | | | | |
| |_____| |_____| |
| _____ _____ |
| | | | | |
| | | | | |
| |_____| |_____| |
| _____ |
| | | |
| | | |
| |_____| |
| |
However, I aim for it to appear as follows:
| _____ _____ |
| | | | | |
| | | | | |
| |_____| |_____| |
| _____ _____ |
| | | | | |
| | | | | |
| |_____| |_____| |
| _____ |
| | | |
| | | |
| |_____| |
| |
Alternatively, on larger screens, my goal is for it to resemble something like this:
| _____ _____ _____ |
| | | | | | | |
| | | | | | | |
| |_____| |_____| |_____| |
| _____ _____ _____ |
| | | | | | | |
| | | | | | | |
| |_____| |_____| |_____| |
| _____ |
| | | |
| | | |
| |_____| |
| |
The key requirement here is that the last row must be aligned to the left rather than being centered within the parent container. Is there a way to achieve this? My attempts so far have not yielded successful results.
Approaches Tried
Using margin: 0 auto proved unfruitful as it necessitates a fixed width, whereas I prefer having as many elements per row as possible.
Exploring a solution involving table layouts also presented challenges since I cannot predict the number of elements fitting on a single line based on the device's characteristics.
Though resorting to JavaScript offers a viable fix, I suspect there may exist a CSS-only resolution to address this issue more elegantly.