Annexes du site

Supports
Glossaire technologies Web
Espace de travail HTML/CSS + Démo

Sources

Classement chronologique :

  1. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification. Version du 7 décembre 2021 / Groupe W3C, B. Bos. W3C, juin 2011. At : https://www.w3.org/cascading-style-sheets-level-2-revision-1 [HTML][Consultation le 4 septembre 2024].
  2. CSS current work & how to participate / B. Bos. In : W3C.org, 29 août 2024. At : https://www.w3.org/CSS-current-work-how-to-participate [HTML][Consultation le 4 septembre 2024].

CSS 2.1 : introduction (1)

Intégration des feuilles de style dans les documents : définition des règles sous l'élément style, lequel viendra se positionner sous l'élément head (en tant que fils), après l'élément title.

Externalisation des feuilles de style : définition des règles dans la feuille de style et intégration de celle-ci (dans les scripts des pages HTML) avec l'élément link, lequel viendra, comme précédemment (avec l'élément style) se positionner sous l'élément head (en tant que fils), après l'élément title.

Introduction des mécanismes d'héritage et de surcharge.

Différence entre unités absolues et unités relatives.

Syntaxe des règles

A rule set (also called "rule") consists of a selector followed by a declaration block.

A declaration block starts with a left curly brace ({) and ends with the matching right curly brace (}). In between there must be a list of zero or more semicolon-separated (;) declarations.

A selector always goes together with a declaration block.

From : Syntax and basic data types. In : [1]. At : https://www.w3.org/syntax-basic-data-types [HTML][Consultation le 10 septembre 2024]. GoTo : section 4.1.7 (Rule sets, declaration blocks, and selectors).

A declaration […] consists of a property name, followed by a colon (:), followed by a property value.

From : Syntax and basic data types. In : [1]. At : https://www.w3.org/syntax-basic-data-types [HTML][Consultation le 10 septembre 2024]. GoTo : section 4.1.8 (Declarations and properties).

Toute règle met en jeu un sélecteur suivi d'un bloc comprenant une ou plusieurs déclarations.

Toute déclaration renvoie à une propriété générale (color par exemple, si on souhaite personnaliser la couleur du texte) à laquelle on appliquera une valeur particulière (blue si on veut du bleu).

Types de données à considérer

Sont ici traités les cas respectifs des longueurs, des URI (et plus particulièrement des URL) et des couleurs, auxquels il faudrait ajouter, pour être complet, ceux des compteurs et des chaînes de caractères.

Cas des longueurs

The format of a length value […] is a number (with or without a decimal point) immediately followed by a unit identifier (e.g., px, em, etc.).

Some properties allow negative length values…

From : Syntax and basic data types. In : [1]. At : https://www.w3.org/syntax-basic-data-types [HTML][Consultation le 4 septembre 2024]. GoTo : section 4.3.2 (Lengths).

Commentaire. — Il est recommandé de ramener la taille des caractères courants à 10 pixels exactement (62,5% des 16 pixels par défaut) de manière à éviter, lorsque le navigateur aura à faire des calculs, pour les en-têtes notamment, les éventuels problèmes d'arrondi : on pourra ainsi passer de 10 pixels à 30 pixels, 20 pixels et 15 pixels (pour les en-têtes de niveau 1, 2 et 3) très facilement et sans approximation aucune, en multipliant tout simplement la taille de base par 3, 2 et 1,5 (1).

Notion d'unité relative

Relative length units specify a length relative to another length property.

The 'em' unit is equal to the computed value of the 'font-size' property of the element on which it is used. The exception is when 'em' occurs in the value of the 'font-size' property itself, in which case it refers to the font size of the parent element.

The rule:

h1 { line-height: 1.2em }

means that the line height of "h1" elements will be 20% greater than the font size of the "h1" elements. On the other hand:

h1 { font-size: 1.2em }

means that the font-size of "h1" elements will be 20% greater than the font size inherited by "h1" elements.

From : Syntax and basic data types. In : [1]. At : https://www.w3.org/syntax-basic-data-types [HTML][Consultation le 4 septembre 2024]. GoTo : section 4.3.2 (Lengths).

Notion d'unité absolue

Absolute length units are fixed in relation to each other. They are mainly useful when the output environment is known. The absolute units consist of the physical units (in, cm, mm, pt, pc) and the px unit:

  • in (inches): 1 in is equal to 2.54 cm.
  • cm (centimeters).
  • mm (millimeters).
  • pt: points (the points used by CSS are equal to 1/72nd of 1 in).
  • pc: picas (1 pc is equal to 12 pt).
  • px: pixel units (1 px is equal to 0.75 pt).
From : Syntax and basic data types. In : [1]. At : https://www.w3.org/syntax-basic-data-types [HTML][Consultation le 4 septembre 2024]. GoTo : section 4.3.2 (Lengths).

Du pixel constant (0,75 pt soit 0,26 mm environ) lié aux longueurs absolues au pixel de référence variable lié à un angle absolu

For lower-resolution devices, and devices with unusual viewing distances, it is recommended […] that the anchor unit be the pixel unit. For such devices it is recommended that the pixel unit refer to the whole number of device pixels that best approximates the reference pixel.

The reference pixel is the visual angle of one pixel on a device with a pixel density of 96 dpi and a distance from the reader of an arm's length. For a nominal arm's length of 28 inches, the visual angle is therefore about 0.0213 degrees.

For reading at arm's length, 1 px thus corresponds to about 0.26 mm (1/96 inch).

...

A reading distance of 71 cm (28 inches) results in a reference pixel of 0.26 mm, while a reading distance of 3.5 m (12 feet) results in a reference pixel of 1.3 mm.

From : Syntax and basic data types. In : [1]. At : https://www.w3.org/syntax-basic-data-types [HTML][Consultation le 4 septembre 2024]. GoTo : section 4.3.2 (Lengths).
Figure 1. Du rapport entre taille du pixel et distance de projection : 0,26 mm à 71 cm (de distance) contre 1,3 mm à 3,5 m.
Rapport entre taille des pixels et distance à l'écran | World Wide Web Consortium (W3C)
Figure 1 (Size of a reference pixel) / B. Bos. In : Syntax and basic data types. In : [1]. At : https://www.w3.org/syntax-basic-data-types [HTML][Consultation le 27 septembre 2024].

Cas des URI et des URL en particulier (1)(2)

The format of a URI value is 'url(' followed by [...] the URI itself […] followed by ')'.

From : Syntax and basic data types. In : [1]. At : https://www.w3.org/syntax-basic-data-types [HTML][Consultation le 4 septembre 2024]. GoTo : section 4.3.4 (URLs and URIs).
  1. URI : terme générique désignant les identifiants des ressources de l'Internet. Ce terme désigne selon les cas soit leur nom propre (leur URN) soit leur nom propre attaché à l'endroit (locator) ou elles se trouvent (c'est-à-dire leur adresse, connue sous le nom d'URL) (a).
  2. C'est pour charger les images dites de décoration (bandeaux, boutons, puces, etc.) des contenus du Web que, dans les feuilles de style, les URL sont utilisées.
  1. « A URI can be further classified as a locator, a name, or both.  The term "Uniform Resource Locator" (URL) refers to the subset of URIs that, in addition to identifying a resource, provide a means of locating the resource by describing its primary access mechanism (e.g., its network "location"). »
    From : Uniform Resource Identifier (URI). Version de janvier 2005 / Groupe de travail Réseau (T. Berners-Lee). In : IETF.org. At : https://www.ietf.org/uniform-resource-identifier [HTML][Consultation le 10 septembre 2024]. GoTo : section 1.1.3 (URI, URL, and URN).

Cas des couleurs

color is either a keyword or a numerical RGB specification.

The list of color keywords is: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, orange, purple, red, silver, teal, white, and yellow.

The format of an RGB value in hexadecimal notation is a '#' immediately followed by either three or six hexadecimal characters.

From : Syntax and basic data types. In : [1]. At : https://www.w3.org/syntax-basic-data-types [HTML][Consultation le 4 septembre 2024]. GoTo : section 4.3.6 (Colors).

Les différents types de sélecteurs et la contextualisation des règles

Les différents types de sélecteurs

A simple selector is either a type selector or universal selector followed immediately by zero or more attribute selectors, ID selectors, or pseudo-classes, in any order.

One pseudo-element may be appended to the last simple selector in a chain.

From : Selectors. In : [1]. At : https://www.w3.org/selectors [HTML][Consultation le 4 septembre 2024]. GoTo : section 5.2 (Selector syntax).

Sélecteur de type d'élément

A type selector matches the name of a document language element type. A type selector matches every instance of the element type in the document tree.

The following rule matches all H1 elements in the document tree:

h1 { font-family: sans-serif }
From : Selectors. In : [1]. At : https://www.w3.org/selectors [HTML][Consultation le 4 septembre 2024]. GoTo : section 5.4 (Type Selector syntax).

Sélecteur d'attribut désignant une classe : sélecteur de classe

Working with HTML, authors may use the period (.) notation as an alternative to the ~= notation when representing the class attribute. Thus, for HTML, div.value and div[class~=value] have the same meaning.

For example, we can assign style information to all elements with class~="pastoral" as follows:

*.pastoral { color: green }  /* all elements with class~=pastoral */

or just

.pastoral { color: green }  /* all elements with class~=pastoral */

The following assigns style only to H1 elements with class~="pastoral":

H1.pastoral { color: green }  /* H1 elements with class~=pastoral */

Given these rules, the first H1 instance below would not have green text, while the second would:

<H1>Not green</H1>
<H1 class="pastoral">Very green</H1>
From : Selectors. In : [1]. At : https://www.w3.org/selectors [HTML][Consultation le 4 septembre 2024]. GoTo : section 5.8.3 (Class Selectors).

Sélecteur d'identifiant

Document languages may contain attributes that are declared to be of type ID. What makes attributes of type ID special is that no two such attributes can have the same value; whatever the document language, an ID attribute can be used to uniquely identify its element.

The ID attribute of a document language allows authors to assign an identifier to one element instance in the document tree. CSS ID selectors match an element instance based on its identifier. A CSS ID selector contains a "#" immediately followed by the ID value, which must be an identifier.

The following ID selector matches the H1 element whose ID attribute has the value "chapter1":

h1#chapter1 { text-align: center }
From : Selectors. In : [1]. At : https://www.w3.org/selectors [HTML][Consultation le 4 septembre 2024]. GoTo : section 5.9 (ID Selectors).

Pseudo-classes

Pseudo-classes classify elements on characteristics other than their name, attributes or content; in principle characteristics that cannot be deduced from the document tree.

From : Selectors. In : [1]. At : https://www.w3.org/selectors [HTML][Consultation le 4 septembre 2024]. GoTo : section 5.10 (Pseudo-elements and pseudo-classes).

Ensemble des pseudo-classes à considérer :

  • Pseudo-classe :first-child (1).
  • Pseudo-classes des liens : :link et :visited (2).
  • Pseudo-classes dynamiques : :hover, :active et :focus (3).
  • Pseudo-classe des langues : :lang (4).

Cas d'usage des pseudo-classes :hover, :active et :visited, avec les liens :

  • La pseudo-classe :hover servira à marquer leur suvol, permettant ainsi d'attirer l'attention sur le fait qu'ils deviennent cliquables.
  • La pseudo-classe :active servira ensuite à marquer leur activation, par le clic, qui typiquement commencera avec la pression du bouton de la souris, pour s'arrêter à sa libération.
  • Et pour finir, la pseudo-classe :visited servira à marquer l'affichage des nouveaux contenus, après libération du bouton de la souris.

Liées au type d'élément considéré, celui des liens hypertextes (5), l'intégration de ces trois pseudo-classes donnera, avec les couleurs que le W3C a retenu dans son exemple (bleu/jaune/citron vert) :

a:visited { color: blue } /* visited links */
a:hover { color: yellow } /* user hovers */
a:active { color: lime } /* active links */
From : Selectors. In : [1]. At : https://www.w3.org/selectors [HTML][Consultation le 12 septembre 2024]. GoTo : section 5.11.3 (The dynamic pseudo-classes: :hover, :active, and :focus).

Remarque. — Au contraire de la pseudo-classe :hover, les pseudo-classes :active et :visited présentent un intérêt qui se discute. Pourquoi en effet faudrait-il changer l'apparence des liens au moment du clic qui, on le sait, ne tient qu'à une fraction de seconde ? Et à l'exception des liens de menus, pourquoi faudrait-il du reste changer l'apparence de liens qui, après le clic, n'apparaîtront plus à l'écran ? les nouveaux contenus des pages visées par les liens ayant chassé (6) les anciens contenus des pages appelantes, avec leurs liens.

  1. Voir Selectors. In : [1]. At : https://www.w3.org/selectors [HTML][Consultation le 12 septembre 2024]. GoTo : section 5.11.1 (:first-child pseudo-class).
  2. Ibid, section 5.11.2 (The link pseudo-classes: :link and :visited).
  3. Ibid, section 5.11.3 (The dynamic pseudo-classes: :hover, :active, and :focus).
  4. Ibid, section 5.11.4 (The language pseudo-class: :lang).
  5. Élément a (a) dans les pages HTML (autant d'éléments que de liens) et type d'élément correspondant dans les feuilles de style (puisqu'il s'agit là d'appliquer un style qui s'appliquera à l'ensemble des liens).
  6. Par rafraîchissement d'écran (dans un onglet), ouverture de nouvel onglet ou encore ouverture de nouvelle fenêtre.
  1. « … represents a hyperlink (a hypertext anchor) labeled by its contents ».
    From : Text-tevel semantics. In : HTML Living Standard. Version du 16 décembre 2024 / Groupe WHATWG, I. Hickson. WHATWG, 2004. At : https://html.spec.whatwg.org/text-level-semantics [HTML][Consultation le 18 septembre 2024]. GoTo : section 4.5.1 (The a element).

Pseudo-éléments

Pseudo-elements create abstractions about the document tree beyond those specified by the document language. For instance, document languages do not offer mechanisms to access the first letter or first line of an element's content. CSS pseudo-elements allow style sheet designers to refer to this otherwise inaccessible information. Pseudo-elements may also provide style sheet designers a way to assign style to content that does not exist in the source document (e.g., the :before and :after pseudo-elements give access to generated content).

From : Selectors. In : [1]. At : https://www.w3.org/selectors [HTML][Consultation le 4 septembre 2024]. GoTo : section 5.10 (Pseudo-elements and pseudo-classes).

Ensemble des pseudo-éléments à considérer :

  • Pseudo-élément :first-line (1).
  • Pseudo-élément :first-letter (2).
  • Pseudo-éléments :before et :after (3).

The :first-line pseudo-element applies special styles to the contents of the first formatted line of a paragraph. For instance:

p:first-line { text-transform: uppercase }

The above rule means "change the letters of the first line of every paragraph to uppercase".

From : Selectors. In : [1]. At : https://www.w3.org/selectors [HTML][Consultation le 4 septembre 2024]. GoTo : section 5.12.1 (The :first-line pseudo-element).
  1. Voir Selectors. In : [1]. At : https://www.w3.org/selectors [HTML][Consultation le 18 septembre 2024]. GoTo : section 5.12.1 (The :first-line pseudo-element).
  2. Ibid, section 5.12.2 (The :first-letter pseudo-element).
  3. Ibid, section 5.12.3 (The :before and :after pseudo-elements).

La contextualisation des règles

The following example combines descendant selectors and child selectors:

div ol > li p

It matches a p element that is a descendant of an li; the li element must be the child of an ol element; the ol element must be a descendant of a div.

From : Selectors. In : [1]. At : https://www.w3.org/selectors [HTML][Consultation le 4 septembre 2024]. GoTo : section 5.6 (Child selectors).

Traitement des polices de caractères

Police de caractères : définition

A typeface (or font family [= police de caractères]) is a design of letters, numbers and other symbols, to be used in printing or for electronic display. Most typefaces include variations in size (e.g., 24 point), weight (e.g., light, bold), slope (e.g., italic), width (e.g., condensed), and so on. Each of these variations of the typeface is a font.

From : https://en.wikipedia.org/wiki/Typeface [HTML][Consultation le 20 septembre 2024].

Les polices de caractères (Times, Arial, Courier…) sont des jeux de caractères « designés » qui comprennent l'ensemble des signes attachés à une langue ou une famille de langues données — lettres, chiffres et autres symboles —, et cela, car ils se doivent d'être complets (pour répondre au besoin de l'utilisateur éditeur des contenus, anciennement compositeur dans le monde de l'imprimerie), dans toutes les tailles, toutes les inclinaisons (pour l'italique) et toutes les épaisseurs de trait (pour le gras) — pour ne retenir que ces trois paramètres, car il y en a d'autres (la capitalisation par exemple).

Attention. — Ne pas confondre polices de caractères et fontes de caractères qui elles désignent les jeux de caractères qu'on aura attachés, notamment, à une taille/une inclinaison/une épaisseur de trait données.

Figure 2. Fontes particulières de la chaîne de caractères « hamburgevons ».
Fontes de caractères | Wikipédia
Figure 1 (Exemples de fontes de caractères). In : Fonte de caractères. In : Wikipédia.org. At : https://fr.wikipedia.org/fonte-de-caracteres [HTML][Consultation le 27 septembre 2024] ❘ File:Hamburgevons.svg [Notice [Image / JamesLucas, 7 juin 2020]]. In : Wikimedia Commons.org. At : https://commons.wikimedia.org/file-hamburgevons-svg [HTML/SVG][Même date de consultation].

Classification des polices de caractères

Se comptant par centaines (1), le W3C a mis en place une classification (2) qui permet de dégager cinq grandes familles de polices. Sont ici introduites les familles serif, sans-serif et monospace, auxquelles il faudrait ajouter pour être complet les familles cursive et fantasy.

Note de fin de section :

  1. Voir List of typeface = Liste des polices de caractères. In : Wikipedia.org. At : https://en.wikipedia.org/wiki/List_of_typefaces [HTML][Consultation le 20 septembre 2024].
  2. Il en existe plusieurs classifications. La plus ancienne, qui appartient aux Chinois, remonte aux X-XIIIe siècles (a).

a. Voir Police de caractères. In : Wikipédia.fr. At : https://fr.wikipedia.org/wiki/Police_de_caract%C3%A8res [HTML][Consultation le 20 septembre 2024]. GoTo : section Classification chinoise.

serif

Glyphs of serif fonts, as the term is used in CSS, tend to have finishing strokes, flared or tapering ends, or have actual serifed endings (including slab serifs). Serif fonts are typically proportionately-spaced.

From : Fonts. In : [1]. At : https://www.w3.org/fonts [HTML][Consultation le 19 septembre 2024]. GoTo : section 15.3.1.1 (serif).
Figure 3. Fonte de caractères avec empattement (serif).
Fonte de caractères avec empattement | Wikipédia
Figure 1. 2e panneau (Serif typeface). In : Serif. In : Wikipedia.org. At : https://en.wikipedia.org/serif [HTML][Consultation le 2 octobre 2024] ❘ File:Serif and sans-serif 02.svg [Notice [Image / D. Remahl, 4 mai 2007]]. In : Wikimedia Commons.org. At : https://commons.wikimedia.org/file-serif-sans-serif-02-svg [HTML/SVG][Même date de consultation].

sans-serif

Glyphs in sans-serif fonts, as the term is used in CSS, tend to have stroke endings that are plain -- with little or no flaring, cross stroke, or other ornamentation. Sans-serif fonts are typically proportionately-spaced.

From : Fonts. In : [1]. At : https://www.w3.org/fonts [HTML][Consultation le 19 septembre 2024]. GoTo : section 15.3.1.2 (sans-serif).
Figure 4. Fonte de caractères sans empattement (sans-serif).
Fonte de caractères sans empattement | Wikipedia
Figure 1. 1er panneau (Sans-serif typeface). In : Sans-serif. In : Wikipedia.org. At : https://en.wikipedia.org/sans-serif [HTML][Consultation le 2 octobre 2024] ❘ File:Serif and sans-serif 01.svg [Notice [Image / D. Remahl, 4 mai 2007]]. In : Wikimedia Commons.org. At : https://commons.wikimedia.org/file-serif-sans-serif-01-svg [HTML/SVG][Même date de consultation].

monospace

The sole criterion of a monospace font is that all glyphs have the same fixed width. (This can make some scripts, such as Arabic, look most peculiar.) The effect is similar to a manual typewriter, and is often used to set samples of computer code.

From : Fonts. In : [1]. At : https://www.w3.org/fonts [HTML][Consultation le 19 septembre 2024]. GoTo : section 15.3.1.5 (monospace).
Figure 5. Fontes de caractères propotionnelle vs monospace.
Fontes de caractères propotionnelle vs monospace | Wikipedia
Figure 1. (Comparison between variable-width fonts and monospaced fonts). In : Monospaced font. In : Wikipedia.org. At : https://en.wikipedia.org/monospaced-font [HTML][Consultation le 2 octobre 2024] ❘ File:Proportional-vs-monospace-v5.svg [Notice [Image / Saucy, 5 février 2021]]. In : Wikimedia Commons.org. At : https://commons.wikimedia.org/file-proportional-vs-monospace-v5-svg [HTML/SVG][Même date de consultation].

Propriétés des polices de caractères

Ensemble des propriétés à considérer :

  • font-style (1).
  • font-variant (2).
  • font-weight (3).
  • font-size (4).
  1. Voir Fonts. In : [1]. At : https://www.w3.org/fonts [HTML][Consultation le 19 septembre 2024]. GoTo : section 15.4 (Font styling: the 'font-style' property).
  2. Ibid, section 15.5 (Small-caps: the 'font-variant' property).
  3. Ibid, section 15.6 (Font boldness: the 'font-weight' property).
  4. Ibid, section 15.7 (Font size: the 'font-size' property).

Présentation du texte (1)

Éléments de bloc : modèle de gestion des bordures et des marges (1)

Figure 6. Du rapport entre marge extérieure (margin), bordure (border) et marge intérieure (padding), autour du contenu (content).
Rapport entre marge extérieure, bordure et marge intérieure | World Wide Web Consortium (W3C)
Figure 1 (Terminology used to refer to pieces of margin, border, and padding) / B. Bos. In : Box model. In : [1]. At : https://www.w3.org/box-model [HTML][Consultation le 27 septembre 2024].