w3resource

CSS color inherit

Color inherit

As we have seen in the previous table that color and inherit these are two values used for color property.We already have seen a few examples of using color value. We will see an example of using the inherit value of the color property.

Here is the css file (say color-inherit.css):

body {
color: teal
}
li {
color: #808000
}

Here is the html file (say color-inhrit.htm) to which the stylesheet above is applied:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>example of external CSS</title>
<link href="color-inherit.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p>We are learning color property of CSS</p>
<ul>
<li>we will learn color property of CSS in this section</li>
</ul>
</body>
</html>

Here is how it will look:

In this example we can see that since it is not mentioned explicitly, color of text contained within p element is teal since it is the color of the body. But since it is explicitly mentioned, color of list item (li) is #808000.

Previous: CSS color units
Next: CSS User Interface



Follow us on Facebook and Twitter for latest update.