The full name of CSS is Cascading Style Sheets, which is translated as Cascading Style Sheets in Chinese. It is a language used to describe the appearance and formatting of web page elements. CSS is an integral part of web design, and it helps us create beautiful, professional web pages.
CSS was first proposed in 1994. At the time, web design relied primarily on HTML, a markup language that was primarily used to describe the structure of web pages. HTML can be used to define the position, size, color, etc., of web page elements, but it is very limited in functionality.
The advent of CSS has made up for the lack of HTML, which provides richer style control. CSS can be used to define the font, color, background, border, shadow, etc. of web page elements, and can also be used to set the layout and animation effects of web pages.
CSS is evolving so fast that it has become an integral part of web design. CSS has become the W3C recommendation and is widely used in a variety of web browsers.
The main functions of CSS are as follows:
Define the appearance and format of web page elements.
Control the layout of your web pages.
Animate web pages.
Implement responsive design for web pages.
The composition of CSS mainly includes the following parts:
Selector: The selector is used to specify the page element to which you want to apply the style.
Attributes: Attributes are used to define the style of web page elements.
Value: The value is used to specify the specific value of the attribute.
The syntax rules of CSS are very simple, and it uses a tag syntax similar to HTML. The basic format of the CSS syntax is as follows:
selector {Property: Value;
Attributes: Value;
For example, the following is used to set the background color of the div element:
div {background-color: red;
The selector in this paragraph is div, the property is background-color, and the value is red. This paragraph sets the background color of the div element to red.
There are many syntax rules for CSS, but here we only cover the most basic ones. For more syntax rules, please refer to the official CSS documentation.
CSS provides a very rich set of properties that can be used to define various styles of web page elements. Here we introduce some commonly used CSS attributes:
color: Sets the color of the font.
font-size: sets the size of the font.
font-family: specifies the font type.
background-color: Sets the background color.
border: Sets the border.
margin: Set the margin.
padding: Sets the padding.
CSS composition and syntax rules.
Selector. The selector is used to specify the web page element to which you want to apply the style. CSS provides a variety of selectors that can be selected based on the element's type, attributes, position, etc.
Commonly used selectors include:
Element Selector: Select elements based on their type, for example: div, p, img, etc.
Class Selector: Selects elements based on their class attributes, for example:class-name。
Tag selector: Select elements based on their tag names, such as a, h1, table, etc.
ID selector: Select an element based on its id attribute, for example: id-name.
Combination Selector: You can select elements based on multiple criteria, e.g. divclass-name#id-name。
Attribute. Attributes are used to define the style of web page elements. CSS provides a very rich set of properties that can be used to define various styles for web page elements, such as:
Font attributes: used to set the style of the font, such as color, font-size, font-family, etc.
Background Attribute: This is used to set the style of the background, for example: background-color, background-image, background-repeat, etc.
Border Properties: Used to set the style of the border, for example: border-style, border-width, border-color, etc.
Layout attributes: used to set the layout of web page elements, such as width, height, margin, padding, etc.
Animation Attributes: Used to animate web page elements, such as animation-name, animation-duration, animation-timing-function, etc.
Value. Values are used to specify specific values for attributes. The value of CSS can be a number, a string, a color value, a unit, and so on.
The notation rules of CSS are basically the same as those of normal text, but there are some special rules.
Common CSS notation rules include:
Semicolon (;) is used to separate multiple attributes. For example, the following ** sets the width of the div element to 100px and the height to 50px:
div {width: 100px;
height: 50px;
The colon (:) is used to specify the relationship between an attribute and a value. For example, the following ** sets the background color of the div element to red:
div {background-color: red;
Equal sign (=): Used to specify the value of the attribute. For example, the following ** sets the font size of the div element to 16px:
div {font-size: 16px;
Double quotation marks ("): Used to represent a string value. For example, the following ** sets the title of the div element to "My Web Pages":
div {title: "My web page";
Single quotation marks ('): Used to represent character values. For example, the following ** sets the id of the div element to "my-div":
div {id: 'my-div';
Space: Used to separate attributes and values, or attributes and attributes. For example, the following ** sets the background color of the div element to red and the text color to black:
div {background-color: red;
color: black;
When using CSS symbols, you should pay attention to the following:
Symbols should use a standard format. For example, a period should be placed in a space at the end of a sentence.
Symbols should be formatted consistently. For example, if there are multiple properties in a CSS rule, all of them should be separated by the same symbol.
Symbols should use correct syntax. For example, in CSS, a colon (:) is used to specify the relationship between a property and a value.
By following the rules of CSS notation, we can write clearer and more readable CSS.
Here are some special uses of CSS notation rules:
An asterisk (*) is used to specify a wildcard. For example, the following ** sets the background color of all div elements to red:
div *
background-color: red;
Symbols: Used to specify CSS rules. For example, the following defines a CSS rule called "my-rule":
my-rule {
background-color: red;
url() function: This function is used to specify the url. For example, the following set the background of the div element to "my-image."jpg”:
div {background-image: url('my-image.jpg');
Symbol: Used to specify the ID selector. For example, the following ** sets the background color of an element with the id "my-div" to red:
#my-div {
background-color: red;
Symbol: Used to specify a class selector. For example, the following ** sets the background color of all elements of the class "my-class" to red:
my-class {
background-color: red;
By understanding CSS notation rules, you can use CSS more flexibly to control the style of your web pages.
CSS is a relatively simple language, and as long as you master the basic grammar rules, you can get started quickly. There are several ways to learn CSS Xi:
Read the official documentation: The official documentation for CSS provides very detailed syntax instructions.
Tutorials: Tutorials can help us intuitively understand the syntax and usage of CSS.
Practice Xi: Through practice Xi we can consolidate our understanding of CSS.
CSS is an integral part of web design, and it helps us create beautiful, professional web pages. The Xi learning method of CSS is very simple, as long as you master the basic grammar rules, you can get started quickly.