CSS Self-Study notes (2): CSS syntax

Source: Internet
Author: User

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
    1. declarations Separated, the attribute and the value are separated by ":". There are many ways to write the values of the
    2. property, such as unit of attention when writing.
    3. If the property value is several words, add quotation marks to the property value.
       p {font-family:  "sans serif" ; 
    4. The
    5. 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;} 
    6. The
    7. 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
    8. CSS is not sensitive to case, but if it involves an HTML file, the case of class and ID names is sensitive
    9. we can group selectors so that multiple selectors can share the same declaration
        H1,H2,  H3,h4,h5,h6  {color:green; } 
    10. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.