CSS syntax structure
selector {property1:value; Property2:value;} If you have more than one property, you need a semicolon at the end of each property. If the value of a property is made up of multiple words, you need to enclose multiple words in quotation marks.types of selectors:
- Element selector-Select HTML element directly: h1{}, a{}
- Selector grouping-You can set the same style for multiple types of labels: h1,a{}
- Wildcard-Sets the style for all HTML tags. A common practice is to use wildcards to set margin and padding to 0px: *{}
- Class Selector-use the. ClassName to specify a class style, which is set in HTML by Class=classname:. class{}
- Element selector + Class Selector-Select the element of a specific type that specifies the class selector: a.class{}
- Multi-class selectors-as the name implies, multiple class styles are applied on the HTML tag. specified in HTML by class= "Class1 Class2" in the style sheet format:. class1.class2{}
- ID Selector-To specify a style for a specific property by #id, simply set the ID for the HTML tag: #id {}
- Property Selector-Specifies the style for HTML with the specified property: [Properties] {}
- Properties and value selectors-similar to the property selector, and attaching a qualification specifies a value for a specific property: [property = value] {}
- Partial property value selector-similar to the property and value selector, in which case only the value of the property is included with the given value: [property~=value]{}
- Descendant Selector-Select the descendant of an element (including child, descendant, descendant, ...): div p a{}, select the A element below the P element below the DIV element
- Child element Selector-Select the child element of an element (only direct descendants can be selected): p>strong{}
- Adjacent sibling selector-selects the element immediately following an element and has the same parent element: h1+p{}, the same level as H1 and immediately following the P element that appears after H1
- Inheritance: Child elements will inherit the style defined on the parent element
[Learning Notes] CSS Selector