In-depth analysis of CSS inheritance (2)

Source: Internet
Author: User
Tags inheritance

In CSS, inheritance is a very natural behavior. We don't even need to consider whether we can do this, but inheritance also has its limitations.
First, some attributes cannot be inherited. There is no reason for this, just because it is set in this way, and the standard is like this. For example, we all know that the border attribute is used to set the border of an element, so it has no inheritance. If the border property is inherited, the document looks strange. For example, we define the border of the container div as 1px, and the ul li in the container normally does not want it to have a border. If the border has Inheritance, we need to remove their borders. This is obviously unreasonable.
Attributes of most Border classes, such as Border, Padding, Margin, and background, are not inherited.
In some cases, inheritance may cause some errors, such as the following CSS definition:
Body {color: blue}
This defines the text color in the Body as blue. If the Body contains a table, this definition in some browsers turns the text except the table into blue, and the text color inside the table is not blue. Technically, this is incorrect, but it does exist. Therefore, we often need to use some techniques, such as defining CSS as follows:
Body, table, th, td {color: blue}
In this way, the text in the table will become blue.

Related Article

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.