Interview Questions

If one were to set Text and Link colors using a style sheet, should one also define the background colors for these elements as well?

CSS Interview Questions and Questions


(Continued from previous question...)

111. If one were to set Text and Link colors using a style sheet, should one also define the background colors for these elements as well?

It is generally true that you should give background or background-color a value, but not necessarily a color value. E.g., if the document has a background image, you would "highlight" all links if you give them a background color.

body { background-image: url(light-texture.png) #FFF; color: #000 }
a:link, a:visited, a:active { color: #00F; background-color: transparent; }

By setting the background-image explicitly to transparent, you lower the risk of another rule in the cascade giving links a background that would highlight them.

(Continued on next question...)

Other Interview Questions