Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

CSS syntax


May 03, 2021 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:

/ * This is a comment * /

p

{

text-align:center;

/ * This is another comment * /

color:black;

font-family:arial;

}