May 03, 2021 CSS
CSS rules consist of two main parts: selectors, and one or more declarations:
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 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:
In describing colors, in addition to using the English word red, we can also use heteenn color values #ff0000:
To save bytes, we can use an abbreviation for CSS:
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.
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;
}