The difference between a Css descendant selector and a descendant selector

Source: Internet
Author: User

Descendants are selected with spaces, such as a b{border:1px solid red;}

A descendant selector, such as a>b{border:1px solid red;}

But if you think about it, these two concepts are not a duplicate of the place,

are descendants also descendants?

are descendants not descendants?

The relationship between the two is not discussed, so let's see what's different in CSS.

First on the code:

<! DOCTYPE html>

Descendant selector:

Descendant selector:

It can be said that the difference is quite large, from the effect can be seen:

Descendants refer to all descendants, while the Offspring refers to the first generation

Is it true?

Let's look at another example:

We modify the CSS code, and the HTML code does not change:

<style>        . Zero ul        {            color:red;        }    </style>

To run using the descendant selector:

Run with the descendant selector:

What the hell, how exactly?

Please note the modification options here, I am not directly using the LI tag,

In addition, I modified the color attribute.

In fact, the above conclusions are still correct.

The situation above, we need to consider the inheritance ,

You know, a property such as color can be inherited, which means

The descendant's font has no default color, so it inherits from the father

Yes, if that's the case, then why didn't it start with inheritance?

The answer is: the border property cannot be inherited and cannot be inherited like border

Also have the following properties:

Display, margin, border, padding,

Background, height, min-height, Max-height,

width, min-width, max-width, overflow, position,

Left, right, top, bottom, z-index, float, clear,

Table-layout, Vertical-align, Page-break-after,

Page-bread-before and Unicode-bidi.

The first 4 of them are measured by me, and the rest is on the network.

Information, accuracy cannot be determined.

That's to figure out why there was a effect,

A situation that does not have the same effect.

The difference between a Css descendant selector and a descendant selector

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.