Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change all link states same color css

Tags:

css

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)

like image 943
David19801 Avatar asked Jan 13 '12 18:01

David19801


People also ask

How do I change the default link color in CSS?

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.

How do I have links of different colors on the same page?

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.

How will you set the color of all the unvisited links in a web page?

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.


2 Answers

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.

like image 87
AlphaMale Avatar answered Nov 07 '22 15:11

AlphaMale


.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;    } } 
like image 30
Grace Shao Avatar answered Nov 07 '22 16:11

Grace Shao