CSS Learning notes-CSS Introduction

Source: Internet
Author: User

1. CSS Definition

CSS refers to cascading style sheets (cascading style Sheets), a Stylesheet language that describes the rendering of HTML or XML documents, including XML branching languages such as SVG, XHTML, and so on. CSS describes the issue of how elements on screen, paper, audio, and other media should be rendered.

2. Why use CSS

Web pages are made up of HTML tags, so these tags will be formatted and styled according to the default browser, if you want to change these default styles, it is recommended to use CSS, because this not only enables the separation of content and performance issues, and easier to maintain.

3. CSS Syntax

CSS syntax consists of two main parts: selectors, and one or more declarations.

selector {declaration1; declaration2; ... declarationn}

Each of these declarations consists of an attribute and a value.

selector {Property:value}

In the following example, H1 is a selector, color and font-size are attributes, and red and 14px are values.

h1 {color:red; font-size:14px;}

This image represents the structure of the above code.

CSS is not sensitive to whitespace and case, that is, the case can be, whether the inclusion of spaces does not affect the CSS in the browser work effect

/**/{    COLOR:   blue;} /*  */{    color: blue;}

The two ways above are shown in the browser are the same.

4. CSS Annotations

Like the HTML language, CSS also has annotations

4.1. Single-line Comment
/**/

Note: Annotations cannot be nested, for example, the following notation is incorrect

/* This is an indication */ Single-line comment * / /* */ */
4.2, multi-line Comment
/**/
5, the introduction of the way 5.1, in-line

Inline is the CSS style that is set in the label's Style property.

<style= "..."></div>
5.2. Embedded

Embedded is the CSS style set in the

<Head>    <MetaCharSet= "UTF-8">    <title>Embedded</title>    ...    <styletype= "Text/css">        ... Write a CSS style here</style></Head>
5.3. Outer-Joint

Write CSS styles in a separate file and then introduce CSS style files via the link tag

<Head>    <MetaCharSet= "UTF-8">    <title>External-linked</title>    ...    <Linkrel= "stylesheet"href= "Outer.css" /></Head>

Type property: Only one option, "Text/css", specifies the current CSS text file
Rel: Specifies that the current HTML file's relationship to the CSS file is a style sheet
HREF: Specifying the path to the outer style sheet

5.4, imported (not recommended)

Write CSS styles in a separate file, then introduce CSS style files via @import tags

<Head>    <MetaCharSet= "UTF-8">    <title>Import type</title>    <styletype= "Text/css">@import URL (css/outer.css); /*Other CSS Styles*/    </style></Head>

Note: The import style must be written before all CSS rules are written, otherwise, importing an external style sheet is similar to linking to an external style sheet, which is equivalent to being used directly in a file, which takes up space in the HTML file, is not recommended, and some browsers will eventually load the imported style, Results in the beginning of the opening of the Web page, there is no style, until the loading is complete before importing the style, the user experience is not good

Another use for importing external style sheets is that if a file needs to refer to many external style sheets, you can put the stylesheet that you want to refer to in a file, and then the file you need to refer to is simply referencing a file, as
IMPORT.CSS content is as follows
@import "A.css"
@import "B.css"
@import "C.css"

In addition to the above 4 imported styles, it is necessary to know that all tags have a default style, which we call a browser style, or a default style. That is, without any style, the HTML tag looks like it is displayed in the browser.

6. Suggestions and points of attention

Some suggestions

    • For future optimization of the code, it is recommended to add a semicolon after each property value, such as: p {font-style:normal;}
    • Some HTML properties have custom default CSS property values, such as:
    • For browser compatibility, it is recommended that you reset the CSS property values for all elements, such as:
    • If you want to use a special font, but also worry that the user does not have the font, you can use the picture instead
    • Set the order of Chinese and English fonts, first set the English font, and then set the font, such as: p {"Courier New", "Arial"}, the proposed font with double quotation marks

Style Application Order

    • In-line style has the highest precedence
    • For the same style attributes, different style properties are rendered in a merged fashion
    • The same style and the same properties, rendered in the order in
    • !important specifying style rules applies top priority

CSS Learning notes-CSS Introduction

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.