The grammar rules of CSS consist of two constituent selectors and declarations (the declaration asks one or more lines).
selector {declaration1; declaration2; ... declarationn}
A selector (selctor) is an HTML element that you want to change the style of. Selectors have many kinds of common ID selectors and class selectors.
A declaration (Declaration) is a property and a value composition (note writing).
Property has a value , and the property and its value are separated by ":".
selector {Property:value}
The basic structure of the above CSS code:
Note:
Use ";" between
- declarations Separated, the attribute and the value are separated by ":". There are many ways to write the values of the
- property, such as unit of attention when writing.
- If the property value is several words, add quotation marks to the property value.
p {font-family: "sans serif" ; The
- defines a declaration in a row to define a declaration, which enhances the readability of the code.
p {text-align:center; Color:black;
font-family:arial;} The
- style sheet can contain multiple rules, the same rule can contain more than one declaration, multi-declaration and reasonable use of space, can effectively increase the readability of the code and compiler's compiler. The
- CSS is not sensitive to case, but if it involves an HTML file, the case of class and ID names is sensitive
- we can group selectors so that multiple selectors can share the same declaration
H1,H2, H3,h4,h5,h6 {color:green; }
- declares an inheritance problem where a child of CSS can inherit a declaration from a parent element, as well as overwrite the declaration of the parent element with its own special declaration.
body {font-family:verdana, sans-serif;
If the declaration of the attribute font-family is not defined in child element a of body, a will inherit the font-family declaration of the body of his parent element.
If the declaration of the attribute font-family is defined in child element B of the body, then the Font-family property of B overrides the declaration of the font-family of the body of its parent element, thus achieving the escape from the parent element declaration