Search code examples
htmlcssz-index

Is it possible that z-index of different CSS can work together?


I'm working on a piece of code where I want to show notification-dropdown over a carousel. For this purpose I'm using z-index property. I have two different CSS files, one for notification-dropdown and other for carousel.

I've given the higher value of z-index for notification-dropdown and lower for carousel. These values are in two different CSS files.

Is it possible that z-index property will work in this case as CSS files for notification-dropdown and carousel are different?


Solution

  • z-index is a property of a box in CSS 2.1 (docs). It should not matter the CSS file it is specified in, as long as it targets the correct box.

    In case a different index is given in more than one file, CSS ambiguity rules apply.

    In order to better understand the concept, CSS make use of Stacking Contexts when rendering content. Appendix E is a good informative article for deeper studies.