I have a spanned class called "tomato".
My css is:
.tomato a:link {color:#FF0000;} /* unvisited link */ .tomato a:visited {color:#FF0000;} /* visited link */ .tomato a:hover {color:#FF0000;} /* mouse over link */ .tomato a:active {color:#FF0000;} /* selected link */
Is there a way I can combine all these into a smaller piece of code? (I want the link to be red in all states)
CSS link color using an HTML tag As far as CSS color is concerned, links, or <a> tags, behave in the same way as regular text. This means to change the color of a link all you need to do is use the CSS color property on the anchor tag with whatever color Hex you want, in the example below we use red.
As seen above, you simply input style="color: ###" in the a href to set it to whatever you want if you wish to set each individual link. :) Show activity on this post. You can also specify style directly for a specific link.
The :link selector is used to select unvisited links. Note: The :link selector does not style links you have already visited. Tip: Use the :visited selector to style links to visited pages, the :hover selector to style links when you mouse over them, and the :active selector to style links when you click on them.
This is the shortest
, I don't think you can do it any shorter than:
.tomato a:link, .tomato a:visited, .tomato a:hover, .tomato a:active { color:#FF0000; }
OR
.tomato { a:link, a:visited, a:hover, a:active { color:#FF00000; } }
Hope this helps.
.tomato a:link, .tomato a:visited, .tomato a:hover, .tomato a:active { color:#F00; }
Note, the color HEX could be abbreviated, too. :)
If you choose to use a CSS framework to organize your CSS such as LESS, it could be much simpler than the above:
.tomato { a:link, a:visited, a:hover, a:active { color:#F00; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With