Hey, aristotletalks!
I seem to have trouble making myself understood, lately … English is not my first language.
What I understand from what you wrote is this: You want a to change the appearance of some element on your page that is added by a plugin. You successfully added custom CSS to your page and when you use !important
that does indeed change the appearance.
I also understood that this would solve your problem except that you don’t want to use !important
. So the question would be: Why doesn’t your custom CSS apply without it?
Is that understanding correct? If so, I was addressing two possible causes for this. A) is a bad thing: If the plugin CSS is like this:
.this-cool-element {
background: pink;
}
And your custom CSS is like this:
.this-cool-element {
background: black;
}
… then both selectors have the same specificity: One class. So the browser applies whichever attribute comes last. You want your custom CSS to be the last <link>
on the page:
<link rel="stylesheet" href="/some-path/plugin.css">
<link rel="stylesheet" href="/some-other-path-doesnt-matter-where/custom.css">
However, if the plugin CSS looks like this:
.some-cool-component .some-cool-child-element {
background: pink;
}
and your custom CSS looks like this:
.some-cool-child-element {
background: black;
}
Then you’re out of luck. .some-cool-component .some-cool-child-element
is a selector with two classes and thus has higher specificity than a selector with one class. Here’s a somewhat wacky overview.
In order to fix this, you have to make sure that your custom CSS selectors have equal or higher specificity. Equal could be simply:
.some-cool-component .some-cool-child-element {
background: black;
}
If it’s higher, the order doesn’t matter. If it’s equal, your custom CSS has to come after.
You can investigate what’s happening with your browser’s developer tools, typically by right clicking on an element and selecting “inspect element” from the context menu. At least the developer tools in Firefox and Chrome are very good. Here’s a screenshot from my browser:
The tool lists all the CSS that would apply by selector rule or by child inheritance, with the once that are overruled being crossed out.
I hope that does contribute to solving your problem and I didn’t completely misunderstand you. It’s, frankly, not a surprise that a menu stops working if you disable its CSS completely.