Is there any way in CSS to set a limit on how far something will cascade?
I am faced with a situation where my CSS just gets out of hand due to how many classes I have to do, due to inheritance. For instance..
.menu a:hover { background : #XXXXXX; } <div class="menu"> <a href="#">Hyperlink</a> <ul> <li><a href="#">Another Hyperlink</a></li> </ul> </div>
Now Another Hyperlink inherits the same style. Now I have two options ... I can change my .menu implementation to this.
.menu > a:hover {
This only makes top-level snap elements. But this is not always what I want. Usually in many cases I have to write more specialized styles for a deeper search in different hierarchies.
In this one instance, I know the solution, but what about more complex scenarios? I have a very bad case of CSS Gone Wild. Now I have more than 20 .css files, and although they are well organized and planned, itβs easy enough to handle. This is normal? Most huge websites have many CSS styles to deal with?
source share