Search code examples
csswidthsetparent

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.


Solution

  • 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.