Css inherit keyword example

What is an example of using the inherit keyword in css?

+3
source share
3 answers

Say we want all of our anchor text to be orange:

a { color: orange }

And we want all our div text to be green:

div { color: green }

What if we want the bindings inside the div to be green too? Here we can use inherit:

div > a { color: inherit }

The following HTML snippet can make this clearer:

<a href="#">I'm orange</a>
<div>I'm green!</div>
<div>I'm green and <a href="#">green</a>!</div>
+6
source
a { color: yellow; }
strong a { color: inherit; }

In the above example, links turn yellow if they are not inside <strong> ... </strong>, in which case they are the default link color for the browser.

inherit , . , CSS .

+2

Source: https://habr.com/ru/post/1727280/


All Articles