Learn more about CSS cascading and inheritance usage

Source: Internet
Author: User
Tags deprecated
1. Three ways to use CSS style sheets in HTML:

(1) inline style sheet.

Eg:<em style= "Background-white" >LIN</em>

(2) embedded style sheet.

That is, the

(3) An externally linked style sheet.

2. Sequence of cascading

(1)

The first thing to do is to classify the rules according to their origins (origin).

The specific priorities are as follows:

Rules > User rules > Browser (browser) rules set by page author (author)

(2)

Then the rules are sorted based on selectors and peculiarities:

1. Inline style sheets have the highest precedence.

2.id Selector, when there are multiple ID selectors, the rule with many ID selectors wins.

3. If there is no ID selector, or the number is the same, then rules with the most class or pseudo-class rules have higher precedence.

4. If the class (or no Class), the rule has the largest number of elements, higher precedence.

5. If id,class, and the number of elements are the same, the most recently declared principle has the highest priority.

(3) The precedence of the embedded style sheet and the external link style sheet, when other weights are equal, the recently declared rule has a high precedence.

In the

3. Cascading and HTML properties

Align,color,face,vlink,background in HTML can also affect the appearance of the page.

The Align property of the tag defines the horizontal and vertical alignment of the image relative to the surrounding elements.

HTML 4.01 does not recommend using the Align property, and the XHTML 1.0 Strict DTD does not support this property, and HTML 5 no longer supports it.

The Color property specifies the colors of the text in the font element.

In HTML 4.01, the color attribute of the font element is deprecated, and the color property of the font element is not supported in the XHTML 1.0 Strict DTD.

Please use CSS instead.

CSS syntax: <p style= "color:red" >

[

<font> Specifies the font, font size, and font color of the text.

Eg:<font size= "3" color= "Red" >this is some text!</font>

<font size= "2" color= "Blue" >this is some text!</font>

<font face= "Verdana" color= "green" >this is some text!</font>

In HTML 4.01, the font element is not approved for use.

In the XHTML 1.0 Strict DTD, the font element is not supported.

]

The Face property specifies the font of the text in the font element.

Eg:<font face= "Verdana" >this is some text!</font>

In HTML 4.01, the face property of the font element is deprecated, and the face property of the font element is not supported in the XHTML 1.0 Strict DTD.

Please use CSS instead.

CSS syntax: <p style= "Font-family:verdana" >

Vlink the color of the link that has been accessed in the properties document.

Eg:<body vlink= "Red" >

In HTML 4.01, the Vlink property of the BODY element is deprecated, and the Vlink property of the BODY element is not supported in the XHTML 1.0 Strict DTD.

Please use CSS instead.

CSS syntax (in

When these properties conflict with CSS rules, they are always overwritten by CSS rules.

4. Use in rules! Important

Use! Important The specified rule is more important than other rules.

Eg:em {Color:bule! important;}

Note: User-initiated! The important rule takes precedence over the author's rules.

User-defined style sheets should be declared Yes! Important

5. @import rules, import files.

eg:h1 {color:red;}

@import url ("Style.css");

/*style.css*/

H1{color:green;}

The above code, the final H1 is red. Because the default is to use imported style sheets before the original style sheet rules.

6. Inheritance

(1) Note that the Display,border,margin,padding property is not inherited.

(2) Background-color is not an inheritance, and when not set, its default value is the special value transparent.

(3) When a relative value is inherited, the value is evaluated first before being passed to the descendant.

(4) Specify inheritance: Inherit special value

Eg:p. standout{border:1px solid Blue;}

P. standout{Border:inhert;}

Note: When CSS 1 is released, the author's! The important style takes precedence over the user! Important style.

CSS2, the user's! The important style takes precedence over the author's! Important style.

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.