Permet une séparation claire de la structure et du style
H1 { color: blue }
Une règle comprend deux parties:
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD>
<TITLE>Titre</TITLE>
<LINK rel="stylesheet" type="text/css"
href="http://style.com/cool" title="Cool">
<STYLE type="text/css">
@import url(http://style.com/basic);
H1 { color: blue }
</STYLE>
</HEAD>
<BODY>
<H1>Titre en bleu</H1>
<P style="color: green">Un paragraphe vert.
</BODY>
</HTML>
H1, H2, H3 { font-family: helvetica }
H1 {
font-weight: bold;
font-size: 12pt;
line-height: 14pt;
font-family: helvetica;
font-variant: normal;
font-style: normal;
}
H1 { font: bold 12pt/14pt helvetica }
H1 { color: blue }
<H1>Le titre <EM>est</EM> important!</H1>
BODY {
color: black;
background: url(texture.gif) white;
}
H1.important { color: #FF0000 }
<H1 class="important">Attention!</H1>
.important { color: #FF0000 }
#z98y { letter-spacing: 0.3em }
<P ID="z98y">Il fait vraiment un temps
incroyable.</P>
P#z98y { letter-spacing: 0.3em }
H1 EM { color: red }
UL LI { font-size: small }
UL UL LI { font-size: x-small }
.reddish H1 { color: red }
#x78y CODE { background: blue }
DIV.sidenote H1 { font-size: large }
H1 B, H2 B, H1 EM, H2 EM { color: red }
EM { color: red } /* red, really red!! */
A:link { color: red } /* unvisited */
A:visited { color: blue }
A:active { color: lime }
P:first-line { font-style: small-caps }
P:first-letter { font-size: 200% }
@import url(http://www.style.org/marine);
/* surchage du style importé */
H1 { color: red }
L'auteur peut interdire la surchage par l'utilisateur:
H1 { color: black ! important }
_______________________________________ | margin (transparent) | | _________________________________ | | | border | | | | ___________________________ | | | | | padding | | | | | | _____________________ | | | | | | | content | | | | | | | |_____________________| | | | | | |___________________________| | | | |_________________________________| | |_______________________________________| | element width | | box width |
Deux types principaux d'éléments: