Propriété shape-outside
La propriété shape-outside permet de définir des formes d'habillage non standard pour les éléments flottants.
Les éléments adjacents vont habiller la forme définie,
et non le conteneur rectangulaire.
Syntaxe
sélecteur {
shape-outside: valeur;
}
Valeurs
| Valeur | Description |
|---|---|
circle() |
Forme d'habillage circulaire |
ellipse() |
Forme d'habillage elliptique |
polygon() |
Forme polygonale arbitraire |
url() |
Forme basée sur le canal alpha d'une image |
margin-box |
Utiliser les limites de la marge (valeur par défaut) |
Exemple
Créons une forme d'habillage circulaire
pour un élément flottant.
Utilisons les propriétés shape-outside et
clip-path:
<div class="shape"></div>
<p>
some long text
</p>
.shape {
width: 150px;
height: 150px;
float: left;
shape-outside: circle(50%);
clip-path: circle(50%);
background: #3498db;
}
p {
width: 500px;
text-align: justify;
}
:
Exemple
Définissons une marge via la propriété shape-margin:
<div class="shape"></div>
<p>
some long text
</p>
.shape {
width: 150px;
height: 150px;
float: left;
shape-outside: circle(50%);
shape-margin: 10px;
clip-path: circle(50%);
background: #3498db;
}
p {
width: 500px;
text-align: justify;
}
:
Exemple
Sans la propriété clip-path le texte
va habiller le cercle, mais l'élément
n'aura pas la forme d'un cercle:
<div class="shape"></div>
<p>
some long text
</p>
.shape {
width: 150px;
height: 150px;
float: left;
shape-outside: circle(50%);
background: #3498db;
}
p {
width: 500px;
text-align: justify;
}
:
Exemple
Une autre forme d'élément:
<div class="shape"></div>
<p>
some long text
</p>
.shape {
width: 200px;
height: 200px;
background-color: #4CAF50;
float: left;
shape-outside: polygon(0% 0%, 100% 50%, 0% 100%);
clip-path: polygon(0% 0%, 100% 50%, 0% 100%);
margin-right: 20px;
margin-bottom: 20px;
}
p {
width: 500px;
text-align: justify;
}
:
Exemple
Une autre forme d'élément:
<div class="shape"></div>
<p>
some long text
</p>
.shape {
width: 200px;
height: 200px;
background-color: #4CAF50;
float: left;
shape-outside: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
margin-right: 20px;
margin-bottom: 20px;
}
p {
width: 500px;
text-align: justify;
}
:
Voir aussi
-
la propriété
clip-path,
qui crée la forme visible de l'élément -
la propriété
float,
nécessaire au fonctionnement de shape-outside -
la propriété
shape-margin,
qui ajoute une marge autour de la forme