Basic CSS knowledge (concept, block-level element, in-Row Element, selector), css Selector
1,CSSConcept
The full name is Cascading Style Sheet. It supports proprietary files with the extension ". css"
Function: separates HTML structures (HTML tags are html) from styles (display styles are css ).
2. CSS syntax structure
Syntax format: Selector {attribute name: Attribute Value;Property name: Property Value;}
2. CSS comments
It is used to explain the code and can be edited at will. The browser ignores it. Format:/* content */
2, How to useCSS
Implemented through the style attribute of HTML elements (<body>), that is, <p> note: the structure and style of HTML are not effectively separated, and this CSS style is only valid for the current element
A. On the
Selector {attribute name: attribute value}
</Style>
B. First define a CSS file, and then introduce the external css file through the <link> element in the HTML page.
That is, <linkHref= "Css file path" rel = "file type. Its fixed value is stylesheet" type = "text/css"/>
[Note: inline styles take precedence over external styles]
3Block-level elements
Concept: exclusive one row on the page (the next block-level element is in the new row)
* <H1>, <p>, <ul>, and <table> have good semantics (specific elements have specific meanings)
[Note: <p> tags cannot contain any block-level elements]
* <Div> element: it does not have any meaning. <Div> </div> the height must be set; otherwise, it cannot be displayed.
Purpose: Implement page layout (similar to <table> table elements)
4, In-row(Inline)Element
Concept: a row is not exclusive (only occupies the area of the text content), such as <td>, <a>, and .
Note: If a row cannot contain all the elements, it will be switched to the next row and arranged from left to right.
<A> a tag cannot contain <a> tags, but can contain any other elements.
[Block-level elements generally contain intra-row elements]
<Span> element: it does not have any meaning. Feature: automatically wrap a line when the line element occupies the entire width of the page.
Eg: <span> </span>
<Span> </span>
Eg: <span> </span>
5,CSSSelector
2. Common Selector
Locate by using the id attribute value of the HTML page element. Its syntax structure is# ID
The class Attribute Value of the HTML page element is located. The syntax structure is. Class
Note: Class names cannot be defined with names starting with numbers. We do not recommend that you use Chinese characters to define class names.
Locate by using the element name of the HTML page element. The syntax structure isElement name
Locate by using the attribute of the HTML page element. The syntax structure is[Attribute name].
[Selector priority: inline style> ID selector> class selector and attribute selector> element selector]
【! Important-set the priority level of the current selector to the highest (disrupt the priority order)-Not recommended]
2. Link Selector
Matching child element based on the target Element
Format: Target element descendant element eg: # t1 div {color: red ;}
Matches child-level elements based on target elements.
Format: Target Element>Child element eg: # t1> div {color: red ;}
- Ø adjacent sibling Selector
Matches the next adjacent sibling element based on the target element.
Format: Target Element+Next adjacent sibling element eg: # t1 + div {color: red ;}
2. Combination Selector
* First-intersection result (multiple selectors are used in parallel without any separation in the middle)
* Method 2-Union result (multiple selectors are used in parallel and separated by commas)
U wildcard selector (*)
Purpose: match all elements in the current HTML page. For example: * {color: red ;}
Problem: the matching speed is not very fast (the number and complexity of page elements)