Login

Bienvenue sur le site de Jef

La foire aux questions

Le problème des défauts du CSS

Le reset CSS est une technique qui consiste à réinitialiser à 0 la valeur de certains éléments HTML afin d'éviter une partie des différences d'affichage sur les divers navigateurs.
Rappelons que l'usage de cette technique est controversé, car par exemple, les navigateurs n'utilisent pas toujours les mêmes marges et padding par défaut pour les différents éléments HTML.
Cela peut représenter un problème, par exemple lorsqu'on veut supprimer le retrait à gauche d'une liste avec un margin-left:0; et que certains navigateurs conservent ce retrait car ils utilisent un padding plutôt qu'une marge. Si vous souhaitez l'utiliser, il est recommandé d'utiliser un Reset CSS évolué, comme celui proposé par Eric Meyer, et d'éviter l'utilisation du sélecteur universel (*).

Ils existent de nombreuses discution sur la façon de faire un reset CSS.

Le reset CSS le plus simple

La façon la plus simple et minimaliste de faire un reset CSS est de définir au tout début de sa feuille de style, les défauts suivant:

html, body 	{ margin:0; padding:0; height:100%; font-size:100%; font-weight:normal; }

Il est bien sûr que vous pouvez définir d'autres styles qui vous sont propres, comme les polices de caractères utilisées, ou le fond d'écran.

body 		{ font-family:"Times New Roman", Times, verdana, arial,sans-serif; }
body 	    { background-color:#fff; }

Comment faire le reset CSS

Ils existent au moins 3 façons de faire le reset CSS.

  1. En utilisant la balise <link> dans la page html juste après la balise <title> et avant </head>
    <link rel="stylesheet" type="text/css" href="/css/defaut.css" />
    <link rel="stylesheet" type="text/css" href="/css/mon-style-a-moi.css" />
    
  2. En ajoutant directement en première ligne de sa feuille de syle (ici mon-style-a-moi.css)
    @import "default-meyer.css";
    ...
    ... mon code css
    ...
    
  3. Ou bien, ajouter directement à la suite de defaut.css, son propre style ...

Défaut CSS html 4

Voici la plus ancienne pour html v4

@charset "utf-8";
/* ================ */
/* Définition des défauts  */
/* ================ */
html, address, blockquote, body, 
dd, div, dl, dt, fieldset, form, frame, frameset,
h1, h2, h3, h4,h5, h6, 
noframes, ol, p, ul, center, dir, hr, menu, pre  { display: block; unicode-bidi: embed }
li                              { display: list-item }
head                            { display: none }
table                           { display: table }
tr                              { display: table-row }
thead                           { display: table-header-group }
tbody                           { display: table-row-group }
tfoot                           { display: table-footer-group }
col                             { display: table-column }
colgroup                        { display: table-column-group }
td, th                          { display: table-cell }
caption                         { display: table-caption }
th                              { font-weight: bolder; text-align: center }
caption                         { text-align: center }
body                            { margin: 8px }
h1                              { font-size: 2em; margin: .67em 0 }
h2                              { font-size: 1.5em; margin: .75em 0 }
h3                              { font-size: 1.17em; margin: .83em 0 }
h4, p, blockquote, ul, fieldset, 
form, ol, dl, dir, menu         { margin: 1.12em 0 }
h5                              { font-size: .83em; margin: 1.5em 0 }
h6                              { font-size: .75em; margin: 1.67em 0 }
h1, h2, h3, h4, h5, h6, 
b, strong                       { font-weight: bolder }
blockquote                      { margin-left: 40px; margin-right: 40px }
i, cite, em, var, address       { font-style: italic }
pre, tt, code, kbd, samp        { font-family: monospace }
pre                             { white-space: pre }
button, textarea, input, select { display: inline-block }
big                             { font-size: 1.17em }
small, sub, sup                 { font-size: .83em }
sub                             { vertical-align: sub }
sup                             { vertical-align: super }
table                           { border-spacing: 2px; }
thead, tbody, tfoot             { vertical-align: middle }
td, th, tr                      { vertical-align: inherit }
s, strike, del                  { text-decoration: line-through }
hr                              { border: 1px inset }
ol, ul, dir, menu, dd           { margin-left: 40px }
ol                              { list-style-type: decimal }
ol ul, ul ol, ul ul, ol ol      { margin-top: 0; margin-bottom: 0 }
u, ins                          { text-decoration: underline }
br:before                       { content: "\A"; white-space: pre-line }
center                          { text-align: center }
:link, :visited                 { text-decoration: underline }
:focus                          { outline: thin dotted invert }
/* Begin bidirectionality settings (do not change) */
BDO[DIR="ltr"]                  { direction: ltr; unicode-bidi: bidi-override }
BDO[DIR="rtl"]                  { direction: rtl; unicode-bidi: bidi-override }
*[DIR="ltr"]                    { direction: ltr; unicode-bidi: embed }
*[DIR="rtl"]                    { direction: rtl; unicode-bidi: embed }

@media print {
  h1                            { page-break-before: always }
  h1, h2, h3, h4, h5, h6        { page-break-after: avoid }
  ul, ol, dl                    { page-break-before: avoid }
}
/* ================ */
/* Fin des défauts             */
/* ================ */

Défaut d'Eric Meyer

À voir aussi les défauts du pape du css à voir sur: Site Meyerweb.com

Voici la version de M. Eric Meyer

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
	margin: 0;
	padding: 0;
	border: 0;
	font-size: 100%;
	font: inherit;
	vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
	display: block;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: '';
	content: none;
}
table {
	border-collapse: collapse;
	border-spacing: 0;
}
/* ====================================== */