Technologies XML / CSS / Recettes CSS / Typographie pour le Web / Lettrines en début de paragraphe

(Extrait de «CSS Kochbuch » de Christopher Schmitt)

Problème

Un paragraphe doit commencer par une lettrine. Le terme lettrines désigne de très grandes lettres au début d’un paragraphe, dépassant le reste du texte de plusieurs points ou atteignant souvent plusieurs lignes de hauteur.

Solution

Placez le paragraphe dans un élément p:

<p>Online, activity of exchanging ideas is sped up. The distribution of messages from the selling of propaganda to the giving away of disinformation takes place at a blindingly fast pace thanks to the state of technology &hellip;</p>

Utilisez maintenant le pseudo-élément :first-letter pour attribuer un style particulier à la première lettre du paragraphe (voir l’illustration suivante) :

p:first-letter {
 font-size: 1.2em;
 background-color: black;
 color: white;
}

Une lettrine simple

Figure : une lettrine simple.

Discussion

Le pseudo-élément de la spécification CSS :first-letter permet de transformer facilement la première lettre d’un paragraphe en lettrine. :first-letter est désormais pris en charge par la plupart des navigateurs modernes, comme Internet Explorer 6 pour Windows, Firefox, Safari et Opera. Pour les autres, l’approche suivante peut aider :

Entourez la première lettre de la première phrase du paragraphe d’un élément span contenant un attribut class:

<p><span class="initcap">O</span>nline, activity of exchanging ideas is sped up. The distribution of messages from the selling of propaganda to the giving away of disinformation takes place at a blindingly fast pace thanks to the state of technology &hellip;</p>

Vous pouvez maintenant définir un style personnalisé pour la première lettre :

p .initcap {
 font-size: 1.2em;
 background-color: black;
 color: white;
}

Voir aussi

La spécification CSS 2.1 concernant le pseudo-élément :first-letter.

  

 

 

 

haut de page