Selector Selector
Each CSS style declaration (definition) consists of two parts, in the following form:
selector { style;}
The part before {} is the selector, and the selector indicates the object of the style in {}, that is, which elements in the Web page the style acts on. The "Body" in the 7th line of code in the right-hand code editor, for example, is the selector.
Tag Selector
The tag selector is actually a tag in the HTML code. such as
P{font-size:12px;line-height:1.6em;}
The effect of the above CSS style code: Set the 12px font size for the P tag, and the line spacing to set the 1.6em style.
Class Selector
Class selectors are most commonly used in CSS style encodings, such as code in the Code Editor: can be implemented as "timid", "courage" font is set to red.
. class Selector name {CSS style code;}
Attention:
1, English dot start
2, where the class selector name can be arbitrarily named (but not Chinese OH)
How to use:
Use the Class= class selector name to set a class for the label as follows:
<class= "stress"> timid </span>
Set the class selector CSS style as follows:
. stress{color:red;} /* Add an English dot in front of the class */
ID Selector
In many ways, the ID selector is similar to a class selector, but there are some important differences:
1. Set id= "ID name" for the label, instead of class= "class name".
2. The ID selector is preceded by the pound sign (#) , not the English dot (.).
Differences between class and ID selectors
same point: can be applied to any element
Different points:
1.The ID selector can only be used once in a document . Unlike class selectors, an ID selector can only be used once, and only once, in an HTML document. The class selector can be used more than once.
< p > in third grade, I was a span class = "stress" > timid </ span >, the little girl of the , never dared to answer the questions raised by the teacher in class, lest the teacher would criticize me for the wrong answer. There was no such
<
span
class
= "stress"
> courage
</
span
> to answer the questions asked by the teacher.
</
p
>
2 . You can use the class selector word list method to set multiple styles for an element at the same time. we can set multiple styles for one element at the same time, but only with the method of the class selector, the ID selector is not possible (the list of ID words cannot be used).
. stress{ color:red;}. bigsize{ font-size:25px;} < P > to <class= "Stress bigsize"> third grade </ span> Next semester, we have a public class in our class ... </ P >
Child Selector
Greater than symbol (>), which selects the first generation of child elements of the specified label element.
. food>li{border:1px solid Red;}
This line of code causes the child element Li under the class name to be added to the red solid line border.
Include (descendant) selectors
A space is added to select the Descendants element under the specified LABEL element .
. First span{color:red;}
Notice the difference between this selector and the sub-selector, where the child selector (children selector) refers only to its immediate descendants, or you can understand the first generation of descendants acting on child elements. The descendant selector is an element that acts on all child descendants. The descendant selector is selected by a space, and the child selector is selected by >.
Summary:> acts on the first generation of descendants of the element, and the space acts on all descendants of the element.
Universal Selector
The universal selector is the most powerful selector, which uses a (*) number designation, which is used to match all tag elements in the HTML, using the following code to use any LABEL element in the HTML font color is all set to red:
* {color:red;}
Pseudo-Class selectors
It allows you to set a style for a tag that does not exist in the HTML (a certain state of the label), such as when we set the font color to the mouse-over state of a tag element in HTML:
a:hover{color:red;}
The previous line of code is to set the font color to red for a-label mouse-over state
About pseudo-selectors:
About pseudo-class selectors, so far, the "pseudo-class selector" that can be compatible with all of the hover is used on a-label: (There are many pseudo-class selectors, especially in CSS3, but because they are not compatible with all the filters, this tutorial is just about one of the most common). In fact: hover can be placed on any label, such as P:hover, but their compatibility is also very bad, so now more commonly used or a:hover combination.
Group Selector
When you want to set the same style for multiple label elements in HTML, you can use the grouping selector (,), which sets the font color to red for the H1, span labels in the Code editor as follows:
h1,span{color:red;}
h1{color:red;} span{color:red;}
Web Front end--html Basic Note No.8