Essentially, my goal is to have the child divs evenly spread out within the parent div. If one of the child divs is removed, I want the remaining divs to resize and fill the space equally again.
For example:
---parent---------------
| -------------------- |
| | child | |
| -------------------- |
| -------------------- |
| | child | |
| -------------------- |
| -------------------- |
| | child | |
| -------------------- |
------------------------
If a child div is removed, the layout should adjust as follows:
---parent---------------
| -------------------- |
| | child | |
| | | |
| | | |
| -------------------- |
| -------------------- |
| | child | |
| | | |
| | | |
| -------------------- |
------------------------
Currently, I am trying to achieve this using only pure HTML/CSS, but I haven't found a solution yet.
Other options I'm considering include:
- Using JavaScript to calculate heights dynamically
- Creating different classes for various scenarios (e.g., parent with 2, 3, or 4 child divs) and loading them accordingly with PHP
Does anyone have a better idea or alternative approach?