One of my challenges involves a parent DIV with a width set to 100%.
Dynamically, this parent DIV is filled with numerous children DIVs.
I am trying to calculate and assign their widths using only the calc method in CSS or LESS. This is because the flex display option doesn't work for me due to working with SVG elements through D3.js.
The desired width formula for each child DIV is: width = (100% / n) - 10
How can I accomplish this task?
In addition, I also need the child DIVs to have alternating colors. I have already figured out how to do this.
Do you have any suggestions on how I can dynamically assign widths using CSS or LESS?
Here is the Jsfiddle link where you can see more details.
Below is the current code I have been working on:
.parent {
width: 100%;
height: 50%;
background: pink;
border: 1px solid red;
min-width: 400px;
min-height: 200px;
}
.child {
min-height: 200px;
min-width: 10px;
border: 1px solid black;
display: inline-block;
}
.child:nth-child(even) {
background: blue;
width: calc(100%/n -10);
}
.child:nth-child(odd) {
background: green;
width: calc(100%/n -10);
}