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

JavaScript to display hidden form text

This article shares the specific code of JavaScri...

How to add shortcut commands in Xshell

As a useful terminal emulator, Xshell is often us...

Detailed explanation of Vue3's sandbox mechanism

Table of contents Preface Browser compiled versio...

How to deploy nginx with Docker and modify the configuration file

Deploy nginx with docker, it's so simple Just...

Pure CSS to implement iOS style open and close selection box function

1 Effect Demo address: https://www.albertyy.com/2...

Postman automated interface testing practice

Table of contents Background Description Creating...

11 Reasons Why Bootstrap Is So Popular

Preface Bootstrap, the most popular front-end dev...

Solve the conflict between docker and vmware

1. Docker startup problem: Problem Solved: You ne...

JS uses clip-path to implement dynamic area clipping function

background Today, I was browsing CodePen and saw ...

Analysis of the reasons why Vue3 uses Proxy to implement data monitoring

Vue data two-way binding principle, but this meth...

CSS text alignment implementation code

When making forms, we often encounter the situati...

Summary of the characteristics of SQL mode in MySQL

Preface The SQL mode affects the SQL syntax that ...

Java programming to write a JavaScript super practical table plug-in

Table of contents Effects Documentation first ste...

Mini Program Custom TabBar Component Encapsulation

This article example shares the specific code for...