Two special values ​​in CSS are used to control the inherit and initial methods of the cascade

Two special values ​​in CSS are used to control the inherit and initial methods of the cascade

There are two special values ​​that can be assigned to any property in CSS to control the cascade: inherit and initial. Let's look at these two special values.

Using the inherit keyword

Sometimes, we want to use inheritance instead of a cascading value. This is when you can use the inherit keyword. You can use it to override another value so that the element inherits the value of its parent element.

Suppose we want to add a light gray footer to our web page. There are some links in the footer, but we don't want them to be too prominent because the footer is not the focus of the web page. Therefore, you need to turn the links in the footer into dark gray (as shown in the figure below).

"Terms of use" link inherits grey text color

Usually we will add a font color to all links on a web page (if not, the user agent style will be used). This color will also be used for the "Terms of use" link in the footer. To make the links in the footer grey, you need to override the color value. Add the following code to your stylesheet.

a:link{ /* (next 3 lines) global web link color*/ 
  color: blue; 
} 
... 
.footer{ 
  color: #666; /* Set the footer text to gray*/ 
  background-color: #ccc; 
  padding: 15px 0; 
  text-align: center; 
  font-size: 14px; 
} 
.footer a{ 
  color: inherit; /* inherits text color from footer */ 
  text-decoration: underline; 
}

The third rule set overrides the blue link color and sets the cascade value of the footer links to inherit. Therefore, it inherits the color of the parent element.

Summarize

This is the end of this article about two special values ​​in CSS used to control the cascade, inherit and initial. For more relevant CSS special values ​​​​to control the cascade, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope that everyone will support 123WORDPRESS.COM in the future!

<<:  Solution to abnormal connection table caused by inconsistent MySQL character sets

>>:  Rhit efficient visualization Nginx log viewing tool

Recommend

Automatic failover of slave nodes in replication architecture in MySQL 8.0.23

I have been in contact with MGR for some time. Wi...

Detailed analysis of the blocking problem of js and css

Table of contents DOMContentLoaded and load What ...

Win10 configuration tomcat environment variables tutorial diagram

Before configuration, we need to do the following...

Vue ElementUI implements asynchronous loading tree

This article example shares the specific code of ...

WeChat applet + ECharts to achieve dynamic refresh process record

Preface Recently I encountered a requirement, whi...

Docker installation and deployment example on Linux

After reading the following article, you can depl...

Summary of seven MySQL JOIN types

Before we begin, we create two tables to demonstr...

Detailed explanation of MySQL user rights verification and management methods

This article uses examples to illustrate how to v...

MySQL 5.7.17 Compressed Version Installation Notes

This article shares the installation steps of MyS...

Simple example of adding and removing HTML nodes

Simple example of adding and removing HTML nodes ...

Example of stars for CSS rating effect

What? What star coat? Well, let’s look at the pic...

Introduction to root directory expansion under Linux system

1. Check Linux disk status df -lh The lsblk comma...

This article will show you how to use Vue 3.0 responsive

Table of contents Use Cases Reactive API related ...

Learn Vue middleware pipeline in one article

Often when building a SPA, you will need to prote...

Tutorial on building svn server with docker

SVN is the abbreviation of subversion, an open so...