Home >Web Front-end >CSS Tutorial >What is the basic syntax of css

What is the basic syntax of css

云罗郡主
云罗郡主Original
2019-03-09 11:41:0318360browse

The basic syntax of css is: 1. CSS rules consist of two parts: a selector and one or more declarations; 2. Selectors are usually HTML elements that need to be changed in style; 3. Each declaration consists of a An attribute is composed of a value; 4. The attribute and attribute value are separated by a colon.

What is the basic syntax of css

CSS Syntax

CSS rules consist of two main parts: the selector, and one or more statement. [Recommended reading: CSS Tutorial]

selector {declaration1; declaration2; … declarationN }

Selectors are usually HTML elements that you need to change the style of.

Each statement consists of an attribute and a value.

The property is the style attribute you wish to set. Each attribute has a value. Properties and values ​​are separated by colons.

selector {property: value}

The following line of code sets the text color within the h1 element to red and sets the font size to 14 pixels.

In this example, h1 is the selector, color and font-size are attributes, and red and 14px are values.

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

The diagram below shows you the structure of the above code:

CSS Syntax

Tip: Please use curly braces to surround declarations .

Different writing methods and units of values

In addition to the English word red, we can also use hexadecimal color values ​​#ff0000:

p { color: #ff0000; }

To save bytes, we can use the CSS abbreviation:

p { color: #f00; }

We can also use RGB values ​​in two ways:

p { color: rgb(255,0,0); }
p { color: rgb(100%,0%,0%); }

Please note that when using RGB percentages, even when the value When it is 0, the percent sign must also be written. But in other cases there is no need to do this. For example, when the size is 0 pixels, there is no need to use px units after 0, because 0 is 0, no matter what the unit is.

The above is the detailed content of What is the basic syntax of css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn