First, CSS common selectorObjective:
The page, all the CSS code, needs to be written to the <style></style> tag.
The Type property of the style label should select "Text/css", but the type attribute can be omitted.
The CSS modifies all the labels on the page and must be selected with the help of a selector.
In the selector, you can write many pairs of CSS properties, wrapped with {}. Between each property name and the attribute value: delimited, multiple-to-attribute, must be used;
Writing:
selector {
Attribute 1: Attribute value 1;
}
(1) Universal selector: 1. notation: *{} 2. Function: Select all labels on the page 3. Priority: lowest (2) Tag selector: 1. Notation: Tag name {} 2. Effect: Select all HTML tags on the page, depending on the selector name. (3) Class selector: (class selector): 1. Notation:. Class name (Note: You must not forget the previous point.Call: In the HTML tag, use the class= "class name" to invoke the selector. 2. Priority: Class selector > tag Selector (4) ID selector: 1. notation: #ID名 {} call: in the HTML tag, use the id= "ID name" to invoke the selector. 2. Priority: The ID selector is larger than the class selector (5) Intersection selector: 1. Notation: Selector 1 selector 2 Selector 3 ... { }multiple selectors are next to each other, without any separation;2. Effect: If a label satisfies the intersection selector, all selectors appearing in the intersection selector must be satisfied, and (6) Set selector 1. notation: selector 1, selector 2, ... Selector n{}.multiple selectors are separated by commas. 2. Rules of entry into force: As long as one of the Assembly selectors is satisfied, it takes effect. (7) Descendant selector 1. Wording: Selector 1 selector 2 ... Selector n{}.selectors are separated by a space2. Rules of entry into force: must be satisfied, after a selector, is the descendants of the previous selector (descendants, grandchildren,), will take effect. (8) Descendant selector 1. notation: selector 1> selector 2> Selector n{}.separator between selectors with >2. Rules of entry into force: must be satisfied, after a selector, is a direct descendant of the previous selector will take effect. Generational, which contains other tags in the middle, does not take effect. (9) Pseudo-class selector (Follow-up explanation)Second, CSS Import mode and priority"Considerations for selectors"1. What is the difference between the ID selector and the class selector?① in different ways:The class selector uses the. Declaration, while the ID selector uses the # declaration.② priorities are different:When acting on the same tag, the ID selector is higher than the class selector ③ in the same HTML file, the ID is unique, soThe ID selector can only work on one label, however, the class selector can be used for n labels. 2. Naming rules for selectors: only: Letters, numbers, underscores, minus signs.cannot begin with a number。 3. Priority ordering for selectors: ① first followsnear PriorityPrinciple. Which selector is used for the innermost label, and which selector takes effect. When ② is used as a label for the same layer, the priority is sorted as follows: The ID selector is larger than the class selector and the tag selector is larger than the universal selector."Selector Priority"1. First principle:Near priority. The selector that acts on the innermost layer takes effect.2. When used as the same layer:Each selector takes precedence and can be calculated: The tag selector takes a weight of 1 class selector takes the weight of the 100 row of the ID selector -Level style sheet style= "" takes the weight 1000Note:Only the intersection, descendants, descendant selectors, participate in the priority of the accumulation!! Instead, the set selector is equivalent to writing two selectors, with no total precedence.3. If the calculated priority weights are exactly the same, the post-write selector takes effect. "Three ways to introduce CSS"1, row-level style sheet:In the HTML tag, use style= "" as a reference; <div style= "height:100px" ></div>Advantages:Flexible to use, highest priority weight.Disadvantages:does not conform to the requirements for the separation of content and performance. is not conducive to style reuse. Code clutter, not conducive to post-maintenance.2. Internal style sheet:In the Head tab, use the style tag to wrap the CSS code.Features:A certain degree of implementation of the separation of HTML and CSS, but the separation is not thorough enough, there is no way to multi-page common style. 3. External style sheet:Write the CSS code to a CSS file, and use the link tag to associate the HTML file with the CSS file. Rel: Select stylesheet type to select "Text/css", which can be omitted. HREF Select the CSS file address. <link rel= "stylesheet" type= "Text/css" href= "Css/01-css.css"/>
Advantages:Completely realize the separation of CSS and HTML, conform to the specifications of the web, in favor of multi-page reuse unified style.
[Two ways to import CSS files]① in the In
Summary, we use the link connection to load the CSS file.
CSS Basic syntax