I’ve been making websites for years and theres on thing that really bugs me and confuses me.
I set a link style in the css file for a content div in my website and this successfully styles the links.
However if i create a span or div inside this div with a new link style i end up having to add in !important to various attributes which i can only tell by trial and error.
Is there any way around this or am I doing something wrong?
Thanks
My intuition is that you’re having problems with your selector specificity.
Ensure that your new link selectors have a higher specificity than the ones in the enclosing element. Normally this would mean using a selector like
div.outerdiv div.innerdiv a.classrather than justa.classetc.For example:
If you use these selectors you may have trouble (depending on css ordering etc.):
Even if you use these selectors, it’s not guaranteed to work how you want:
However, these selectors should work best, ensuring your innerlinks override attributes:
Make sure you specify all the attributes you want to override in the .innerlink css.
Once you understand specificity, the power of the darkside will be yours.