Kevin Kevin - 3 months ago 16
Less Question

Styling links (<a> tag) for all selectors at the same time with Less/CSS?

Say I want to make all links on my page red, no matter if its is selected/visited/active or not. Normally I would do

a:link, a:visited, a:hover, a:active{
color: red;
}


Is there a shorter way of doing this using Less or standard CSS?

Answer

Anything involving LESS is actually going to end in more code, ironically.

If you don't care about named anchors and specificity is not an issue:

a {
    color: red;
}

If you have named anchors (which are not links) and you don't want these to be affected, or if specificity is an issue for you:

a[href] {
    color: red;
}

If specificity is still an issue, such as when you have even more specific competing CSS rules matching your links (or any of their individual states) overriding this rule, you'd have to resort to something really horrible like !important if you don't know the competing rules in advance.

Comments