Basic CSS syntax:
CSS styles are mainly composed of three parts:
. Selector
. Attribute name
. Attribute Value example:
<HTML>
<Head>
<Title> basic CSS syntax </title>
<Style type = "text/CSS">
P {color: # aa66cc}
H2 {text-align: center; color: Red}
P. mystyle1 {font-size: 20px; color: Blue}
P. mystyle2 {font-style: italic; font-size: 40px;
Color: #00 FFFF; text-align: Center}
H1, H3, H4, H5, H6, P. mystyle3 {text-align: center; color: Green}
. Mystyle {text-align: Right; color: # ff00ff}
</Style>
</Head>
<Body>
<H2> H2 title text </H2>
<H5> H5 title text </H5>
<P class = "mystyle1"> first paragraph </P>
<P class = "mystyle2"> second paragraph </P>
<P class = "mystyle3"> the third paragraph </P>
<P> fourth paragraph </P>
<P class = "mystyle"> fifth text </P>
<H4 class = "mystyle"> H4 title text </H4>
<Div class = "mystyle"> text in the DIV block </div>
</Body>
</Html>
CSS comments:
/* Like a comment in Java, it can be cross-line */CSS font attributes:
Main font attributes include:
. Font-family
Set the font type, such as "Arial" and "".
. Font-size
Set the font size. common measurement units: PT and PX.
. Font-style
Set the font style. Optional values: Normal, italic, and oblique.
. Font-weight
Set the font "weight". The common values are normal and bold.
. Font
Comprehensively set the above font attributes
Example: <HTML>
<Head>
<Title> CSS font attributes </title>
<Style type = "text/CSS">
P. mf1 {Fon-size: 20px}/* courier offset */
P. mf2 {Font: normal italic bold 20pt}
</Style>
</Head>
<Body>
<P class = "mf1"> the first paragrah </P>
<P class = "mf2"> second paragraph </P>
</Body>
</Html> common CSS text attributes:
. Text-align
Sets the text alignment mode. Optional values: Left, center, right, and justify)
. Text-indent
Sets the indent of the first line. The value can be an absolute or relative length unit and percentage.
. Line-height
Set the row height. The value can be an absolute or relative length unit and percentage.
. Letter-spacing
Sets the Character spacing. The value can be an absolute or relative length unit.
. Color
Text color setting example:
<HTML>
<Head>
<Title> common CSS text attributes </title>
<Style type = "text/CSS">
. T1 {text-align: Left; text-indent = 1 cm; line-Height = 20px; letter-spacing = 150%; color = Red}
. T2 {text-align: center; text-indent = 0; letter-spacing = 1em; color = blue; font-weight: bold}
/* Em is the distance of a character */
</Style>
</Head>
<Body>
<P class = "T1"> in ancient Greece, a saying goes: "smart people speak with experience. smarter people do not speak with experience ." There is also a famous saying in the West: eloquence is silver, and listening is gold. In China, there are famous sayings like "too many words to lose" and "too easy to understand. </P>
<P class = "T2"> sailing on the side of the boat, with the health tree in front of the tree </P>
</Body>
</Html> unit of CSS length:
In the CSS style sheet, the unit of length is divided into two types:
1). Absolute length unit
Absolute length unit description
In inch inches (1 inch = 2.54 cm)
CM cm centimeters
Mm mm millimeters
PT point points (1 point = 1/72 inch)
PC pickup PICAS (1 pickup =)
2). Unit of relative length:
Description of relative length units
Font height of the EM Element
The height of X
Px pixel pixels
% Percentage