I have a parent DIV with widht 100%;
Now, on the fly, it is populated with n number of children DIVs.
Now, I want to be able to caclulate and assign their width in CSS or LESS using calc method only (flex display doesnt work in my actual code which does not actually just deals with DIV s but actually svg elements using d3) so that their width is in this pattern
width of n-th child DIV = (100% / n) - 10
How can i achieve that?
Also, the DIV s need to be of alternative colors which i have managed to figure out how?
Any ideas how can I assign width on the fly using css or less?
http://jsfiddle.net/7r029v9n/2/ - here is the Jsfiddle
here is my code so far
.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);
}