arik
arik

Reputation: 29270

CSS set width to parentNode's width

Is there a way in CSS to set the width of any element to equal the width of its parentNode? I tried 'inherit' - sounds logic - but it didn't work.

Thanks in advance.

Upvotes: 5

Views: 20816

Answers (2)

animuson
animuson

Reputation: 54729

Depending on what element it is, setting the CSS property display: block will usually make it automatically fill all possible width, aka stretch to its maximum without overflowing on padding or borders.

Upvotes: 1

Razor
Razor

Reputation: 29628

width: 100%;

This means 100% of the parent element's width.

Note that it might not work if the element has the display property set to something different to "block", and in a few other cases.

If you try it on 2 nested divs, it'll work.

Upvotes: 6

Related Questions