Let's say I have a parent div with a fixed width of 320 pixels, and I want to be able (or I want my users to be able to) add any number of child divs to the parent element, and they all automatically adjust to divide the width of the parent.
I don’t want to change the width of the parent element and I don’t want to do this with any scroll overflow - I just need the divs inside to match the width of the parent equally.
For instance,
If there is only one child, then the width is 100%, if there are two, then their width is 50%, etc.
How should I do it?
I approached this in many different ways using css, but didn't seem to get it. I assume this needs to be done using some kind of javascript, but I don't know how to do it.
But, if this can be done using only css, that would be great.
Thanks in advance.
(I don’t know if I need to know this, but the child divs have no text. They are just empty with a background color and a fixed height)
Code example:
CSS
.box { margin: 10px; background: white; border-radius: 6px; border: 1px solid darken(white, 12%); -webkit-box-shadow: 0px 1px 4px rgba(50, 50, 50, 0.07); -moz-box-shadow: 0px 1px 4px rgba(50, 50, 50, 0.07); box-shadow: 0px 1px 4px rgba(50, 50, 50, 0.07); float: left; } .line { height: 6px; opacity: 0.4; -moz-opacity: 0.4; filter:alpha(opacity=4); margin-bottom: -1px; float: left; }
HTML
... <div class="box"> <div class="line"> </div> </div> ... #will be able to add any amount of .lines