How to relate width in percent to the grand parent?
Asked
Active
Viewed 735 times
0
-
Is the grandparent going to be full width of the page? – James Donnelly Jul 10 '15 at 08:26
-
No that is not the case. I know how to work around if it was full with of the page, but no it is not. It has a dedicated width – Peyman Mohamadpour Jul 10 '15 at 08:28
2 Answers
1
You could simply relate width of li
s to the parent ul
which in turn it relates to the grand parent div
:
div{
overflow: hidden;
width: 100%;
}
ul{
width: 1000%;
}
li{
width: 3%;
}

Peyman Mohamadpour
- 17,954
- 24
- 89
- 100
0
Use javascript:
var g = document.getElementById('grandparent');
var w = g.clientWidth;
if (w > 400)
w *= .3;
var c = document.getElementsByClassName('child');
for (var i=0; i < c.length; i++) {
c[i].style.width = w+'px';
}
I have a jsfiddle example.

Zectbumo
- 4,128
- 1
- 31
- 26
-
thats not a matter of JS, as I did not tag the question using JS and tags & title say question is CSS. by the way thanks for your answer – Peyman Mohamadpour Jul 13 '15 at 21:05