Propriété widowsde Style
Objet Style
Définition et utilisation
La propriété widows définit ou renvoie le nombre minimum de lignes visibles qu'un élément doit avoir en haut d'une page (pour l'impression ou l'aperçu avant impression).
La propriété widows n'affecte que les éléments de niveau bloc.
Astuce :widows:5 signifie qu'au moins 5 lignes doivent être visibles sous un saut de page.
Astuce :La propriété orphans définit ou renvoie le nombre minimum de lignes visibles qu'un élément doit avoir au bas d'une page.
Syntaxe
Définition de la propriété widows :
Object.style.widows="number|inherit"
Renvoi de la propriété widows :
Object.style.widows
| Valeur | Description |
|---|---|
| nombre | Un entier qui spécifie le nombre minimum de lignes visibles. La valeur par défaut est 2. |
| inherit | La valeur de la propriété widows est héritée de l'élément parent. |
Prise en charge des navigateurs
![]()
![]()
![]()
![]()
![]()
Seul Opera prend en charge la propriété widows.
Exemples
Exemples
Modifier la propriété widows pour l'impression ou l'aperçu avant impression :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutoriel d'exemple (example.com)</title>
<script>
function ChangeWidows(){
document.getElementById("p1").style.widows=document.getElementById("widows").value;
}
</script>
<style>
.othercontent{
width:400px;
border-top:19cm solid #c3c3c3;
}
@page{
/* Définir la taille de la page d'impression */
size:21cm 27cm;
margin-top:2cm;
}
@media print{
.widows{
widows:2;
}
}
</style>
</head>
<body>
<div class="othercontent">
<input id="widows" value="2"/>
<button onclick="ChangeWidows();">Modifier la fenêtre</button>
<p style="font-size:120%" id="p1">
Modifier la fenêtre et afficher l'aperçu avant impression<br>
Ligne 2<br>
Ligne 3<br>
Ligne 4<br>
Ligne 5<br>
Ligne 6<br>
Ligne 7<br>
Ligne 8<br>
</p>
<div class="othercontent"></div>
</div>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Tutoriel d'exemple (example.com)</title>
<script>
function ChangeWidows(){
document.getElementById("p1").style.widows=document.getElementById("widows").value;
}
</script>
<style>
.othercontent{
width:400px;
border-top:19cm solid #c3c3c3;
}
@page{
/* Définir la taille de la page d'impression */
size:21cm 27cm;
margin-top:2cm;
}
@media print{
.widows{
widows:2;
}
}
</style>
</head>
<body>
<div class="othercontent">
<input id="widows" value="2"/>
<button onclick="ChangeWidows();">Modifier la fenêtre</button>
<p style="font-size:120%" id="p1">
Modifier la fenêtre et afficher l'aperçu avant impression<br>
Ligne 2<br>
Ligne 3<br>
Ligne 4<br>
Ligne 5<br>
Ligne 6<br>
Ligne 7<br>
Ligne 8<br>
</p>
<div class="othercontent"></div>
</div>
</body>
</html>
Essayez-le vous-même »
Objet Style Autres extensions