I realize I am late to the conversation, but using an indeed non-existent ID selector, such as "#dummy", is by far the most efficient way to increase CSS specificity and the :not
and :is
pseudo-classes should be used.
This method can be utilized even if no ID or class is not present in the HTML!
This is a perfectly valid way to greatly increase specificity, for example:
ul li:not(#dummy)
On the other hand, an example with little less specificity would be:
ul :is(li)
These two examples both have greater specificity than a standard ul li
selector.
To experiment with different selectors and their specificities, you can use a specificity calculator such as the one found at: Specificity Calculator
I'm not sure that most readers have understood how flexible :not(X)
is in terms of adjusting specificity. I encourage you to experiment with the specificity calculator. What can be achieved is a fine tuning of the specificity value. Exact specificity can easily be adjusted at will.
For example, ul li:not(#i#i#i#i.c.c.c)
has a weight of 4 x ID and 3 x class. If you need it with 3 x ID, you can use ul li:not(#i#i#i)
, or for a slight boost, you can use ul li:not(.c.c)
, which increases it by 2 x class.
Moreover, all this can be done without touching HTML classes or IDs in any way, which is the main idea behind this method.
html
? Are the styles being overwritten? Why not just include that stylesheet after the others if they're using the same selector – Takenhtml
can be improved upon – Machinate