CSS width in percent associated with great parent

How to associate the percentage width with a great parent?

CSS Responsive thumbnail slider

0
source share
2 answers

You can simply associate the width of li with the parent ul , which in turn refers to the grand parent div :

 div{ overflow: hidden; width: 100%; } ul{ width: 1000%; } li{ width: 3%; } 
+1
source

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 .

0
source

All Articles