CSS Learning Note 1

Source: Internet
Author: User

Priority questions about selectors:

One of the most vivid things you can see in CSS is that he creates a priority score to measure the precedence of a selector:

Tag Selector, pseudo-class pseudo-element, priority integral is 0;

class Selector, attribute selector, priority integral is 10;

ID Selector, priority integral is 100;

The style attribute within the tag, priority integral is 1000;

Other selectors, such as wildcards and so on, have priority points of 0;

There is also a!important, his priority is positive infinity ...

Here are some differences between adjacent selectors and sub-selectors:

Look at the code first:

 1  <  body  >  2  <  p  >  againd </ p  >  3  <  strong  >  wants to is a good JavaScript developer. </ strong  >  4   Body  >  

In cases where the sub-selector and the adjacent selector are only considered, there are two ways to select the <strong> tag:

1{2    //the style ...   3 }45{6//the style ...      7 }

At this point the two options are completely equivalent, and can not see what ...

Look at the bottom again!

1 <Body>2     <P>Againd</P>3     <Strong>Wants to is a good JavaScript developer.</Strong>4     <Strong>He also wants to be a good student!</Strong>5 </Body>

Look, now you want to use Body > strong{//...} If you select <strong>, both are selected, and P + strong {} is still only the first one, but if you think it's all, it's a big mistake!

... Here's another piece of code:

1 <Body>2 <P>Againd</P>3 <Strong>Loves</Strong>4 <Strong>Himself</Strong>5 <Strong>Adnby</Strong>6 <Strong>His mother</Strong>7 <Strong>His father</Strong>8 </Body>

For the above code, if you use P + strong to select <strong>, you will get the first <strong> tag, but you use strong + strong to make a selection, you will find that except for the first <strong> , the other four <strong> tags will be selected, and the four <strong> can be interpreted as a <strong> tag that is adjacent to the <strong> tag.

CSS Learning Note 1

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.