Posts in current category

CSS syntax


May 03, 2021 20:00 CSS


Table of contents


CSS syntax



CSS instance

CSS rules consist of two main parts: selectors, and one or more declarations:

CSS syntax

The selector is usually the HTML element that you need to change the style.

Each declaration consists of a property and a value.

A property is a style attribute that you want to set. E ach property has a value. The property and the value are separated by a colon.


CSS instance

CSS declarations are always made with a half sign ( ; ) ends, and the declaration group is enclosed in { } ( .

p {color:red;text-align:center;}

To make CSS more readable, you can describe only one property per line:

p
{color:red;
text-align:center;}

Try it out . . .

How CSS color values are written

In describing colors, in addition to using the English word red, we can also use heteenn color values #ff0000:

p { color: #ff0000; }

To save bytes, we can use an abbreviation for CSS:

p { color: #f00; }

We can also use RGB values in two ways:

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

Tip: When using RGB percentages, write percentage symbols even when the value is 0. B ut in other cases it is not necessary. F or example, when the dimension is 0 pixels, px units are not required after 0.

In the programming practice section of this site, you can refer to the content of this section to learn more about CSS setting colors using heteen code and CSS setting colors using rgb properties.


CSS comments

Comments are used to interpret your code and can be edited at will, and the browser ignores it.

The CSS comment begins /* " , ends with " / */ , with the following example:

/*这是个注释*/

p

{

text-align:center;

/*这是另一个注释*/

color:black;

font-family:arial;

}