Tuesday, 12 April 2016

CSS Color

The CSS color property defines the foreground color for an element.

Setting Color Property

The color property typically defines the color of the text content of an element.
For instance, the color property specified in the body selector defines the default text color (foreground color in general) for the whole page.

Example


  • body {
  •     color: #000000;
  • }
Colors in CSS most often specified by the following methods:
  • a HEX value - like "#ff0000"
  • an RGB value - like "rgb(255,0,0)"
  • a color name - like "red"

Affect of Color Property on Borders and Oulines

The color property is not just for text content, but for anything in the foreground that takes a color value. For instance, if border-color or outline-color value hasn't been defined explicitly for the element, the color value will be used instead.

Example


  • p.one {
  •     color: #0000ff;
  •     border: 2px solid;
  • }
  • p.two {
  •     color: #00ff00;
  •     outline: 2px solid;
  • }
 
Note:The color property normally inherits the color value from their parent element, except the case of anchor elements.

No comments:

Post a Comment