CSS style sheet, CSS selector _css

Source: Internet
Author: User

1 briefly describe how CSS style sheets are used.
There are three ways to use CSS style sheets in HTML pages:
1, inline style sheet: style rules in a single element, written in the element's style attribute;
2. Internal style sheet: The style definition is in the header element of the HTML page;
3. External style sheet: Defines the style in an external CSS file and then refers to the stylesheet file by the HTML page.

2 How to understand the layering of CSS style sheets.
CSS uses the cascade (Cascade) principle to consider important features such as inheritance, cascade order, and precedence to determine which rule in conflicting rules should work.
Inheritance means that many CSS style rules affect not only the elements defined by the selector, but also the descendants of those elements.
Cascading means that when a Web page uses multiple style sheets, the styles in multiple style sheets can be stacked into one. When there is no conflict between the styles defined by multiple style sheets, the browser displays all the styles.
Precedence means that when a style definition conflict occurs, the browser first applies the style according to the precedence of the different style rules. The precedence of CSS styles is shown below (where the number 3 has the highest priority):
1, browser default settings;
2, external style sheet (. css file) or internal style sheet (located within < head> elements);
3, inline style (as the value of the style property of an element).
The same priority, whichever is the last defined style.

The difference between the element selector and the class selector in the

3 CSS selector. The
Element selector is the most common CSS selector, that is, the element of the document is the most basic selector. Selectors are usually an HTML element, such as < p>, < h1>, < em>, < a>, or even the < html> element itself. The
Class selector is used to match a style rule with an element that comes with a class attribute, where the value of the Class property is the value specified in the class selector. When you use the class selector, you first need to define the style class, which has the syntax:
. ClassName {}
All elements that can accompany the class attribute can use this style declaration. You can associate the style of a class selector with an element by simply setting the value of the class attribute to "ClassName".
when used, the element selector is often used if you need to define a style for an element, and if you want to apply a style without considering the elements of a specific design, the most common method is to use the class selector.

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.