Use of the CSS currentColor variable

Source: Internet
Author: User

Use of the CSS currentColor variable
CSS contains a mysterious variable, which is rarely known and rarely used. It is the crrentColor variable (or CSS keyword, but I think it is better to understand it ). What is it? What are the benefits? Where does it come from? Continue with these questions. The following is an explanation from MDN: currentColor represents the color value applied to the current element. It can be used to apply the current color value to other attributes or other attributes of nested elements. You can understand this. In CSS, you can use the currentColor variable wherever you need to write the color. The value of this variable is the color value of the current element. If the current element does not display a color value in CSS, its color value follows the CSS rule and is inherited from the parent element. It seems that the above three philosophical questions have been solved, but they are still vague. The communication between programmers should be on code. Scenario 1 <p> about? </P> p {color: red;} at this time, the value of <p> label currentColor is red. Scenario 2 <div class = "container"> <p> about? </P> </div>. container {color: #00ff00;} now, we have not specified a color for the <p> label. Its color is inherited from the parent container, that is, the class is the div of the container, in other words, the color of the p tag is #00ff00, and currentColor is directly used to retrieve the color value of the element. Therefore, the currentColor value of the p tag is #00ff00. What if no color is written for the parent element? In fact, it is still the category of CSS rules, and it has little to do with the main character of this article. However, based on the principle that the system will die, we will start to talk about it. If no color is specified for a parent element, its parent element will inherit from the parent element, until the html tag at the root node of the document is not displayed with a specified color, the default color of the browser will be applied ~ <! Doctype html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.