« CSS » : différence entre les versions
De bricosoft
m Remplacement des balises <source> obsolètes par <syntaxhighlight> (bot) |
|||
| (Une version intermédiaire par un autre utilisateur non affichée) | |||
| Ligne 1 : | Ligne 1 : | ||
'''CSS''' s'approche plus du Content Scrambling System que du Cascading Style Sheet. | '''CSS''' s'approche plus du Content Scrambling System que du Cascading Style Sheet. | ||
| Ligne 6 : | Ligne 4 : | ||
Pour un sticky footer, il faut en premier sortir le div footer du DOM principal : | Pour un sticky footer, il faut en premier sortir le div footer du DOM principal : | ||
< | <syntaxhighlight lang="html4strict"> | ||
... | ... | ||
</head> | </head> | ||
| Ligne 18 : | Ligne 16 : | ||
</body> | </body> | ||
</html> | </html> | ||
</ | </syntaxhighlight> | ||
Son style : | Son style : | ||
< | <syntaxhighlight lang="css"> | ||
#ft { | #ft { | ||
position: relative; | position: relative; | ||
| Ligne 28 : | Ligne 26 : | ||
clear: both; | clear: both; | ||
} | } | ||
</ | </syntaxhighlight> | ||
== px vs em vs pt vs %== | == px vs em vs pt vs %== | ||
| Ligne 39 : | Ligne 37 : | ||
*background-color | *background-color | ||
*background-image | *background-image | ||
< | <syntaxhighlight lang="css"> | ||
background-image:url('paper.gif'); | background-image:url('paper.gif'); | ||
</ | </syntaxhighlight> | ||
*background-repeat | *background-repeat | ||
*background-attachment | *background-attachment | ||
| Ligne 49 : | Ligne 47 : | ||
Dans l'ordre décroissant de performances : | Dans l'ordre décroissant de performances : | ||
< | <syntaxhighlight lang="css"> | ||
/* par ID ★★★ */ | /* par ID ★★★ */ | ||
#trucmuche {...} | #trucmuche {...} | ||
| Ligne 64 : | Ligne 62 : | ||
/* universel */ | /* universel */ | ||
* {...} | * {...} | ||
</ | </syntaxhighlight> | ||
Bonnes pratiques : | Bonnes pratiques : | ||
< | <syntaxhighlight lang="css"> | ||
/* ID */ | /* ID */ | ||
#boutonRetour {…} | #boutonRetour {…} | ||
| Ligne 78 : | Ligne 76 : | ||
.classement-important {…} | .classement-important {…} | ||
</ | </syntaxhighlight> | ||
A éviter : | A éviter : | ||
< | <syntaxhighlight lang="css"> | ||
/* le tag html avant id */ | /* le tag html avant id */ | ||
button#boutonRetour {…} | button#boutonRetour {…} | ||
| Ligne 87 : | Ligne 85 : | ||
/* une classe + id */ | /* une classe + id */ | ||
.classement-important#iconMenu {…} | .classement-important#iconMenu {…} | ||
</ | </syntaxhighlight> | ||
*sources : [https://developer.mozilla.org/en/Writing_Efficient_CSS dev.moizilla.org] | *sources : [https://developer.mozilla.org/en/Writing_Efficient_CSS dev.moizilla.org] | ||
Dernière version du 8 novembre 2026 à 17:46
CSS s'approche plus du Content Scrambling System que du Cascading Style Sheet.
stickyfooter / pied-de-page collé
Pour un sticky footer, il faut en premier sortir le div footer du DOM principal :
...
</head>
<body>
<div class="principal">
... plein de trucs supers
</div>
<div id="ft">
<p>Footer.</p>
</div>
</body>
</html>
Son style :
#ft {
position: relative;
margin-top: -100px;
height: 100px;
clear: both;
}
px vs em vs pt vs %
- px : reliable but not for printing
- em : reliable and depends on browsers
- pt : for printing
- % : depends on browsers
background
- background-color
- background-image
background-image:url('paper.gif');
- background-repeat
- background-attachment
- background-position
Performances
Dans l'ordre décroissant de performances :
/* par ID ★★★ */
#trucmuche {...}
body.superclass #totoche {...}
/* par classe ★★ */
.bavette {...}
ul ol a.cerveau {...}
/* par tag ★ */
ul {...}
ul li a {...}
/* universel */
* {...}
Bonnes pratiques :
/* ID */
#boutonRetour {…}
#iconMenu {…}
/* classe */
.cellule-rouge {…}
/* encore plus classe avec sémantique */
.classement-important {…}
A éviter :
/* le tag html avant id */
button#boutonRetour {…}
/* une classe + id */
.classement-important#iconMenu {…}
- sources : dev.moizilla.org
Liens
- css et clients emails : http://www.campaignmonitor.com/css/