Peyman Mohamadpour
Peyman Mohamadpour

Reputation: 17944

CSS width in Percent related to the grand parent

How to relate width in percent to the grand parent?

CSS Responsive thumbnail slider

Upvotes: 0

Views: 763

Answers (2)

Zectbumo
Zectbumo

Reputation: 4471

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.

Upvotes: 0

Peyman Mohamadpour
Peyman Mohamadpour

Reputation: 17944

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%;
}

Upvotes: 1

Related Questions