Dans ce chapitre, vous apprendrez à refléter une image.
La propriété box-reflect est utilisée pour créer un reflet d'image.
La valeur de la propriété box-reflect peut être :
below
above
left
rightLes nombres dans le tableau spécifient la première version du navigateur qui prend entièrement en charge la propriété.
Les nombres suivis de -webkit- spécifient la première version qui a fonctionné avec un préfixe.
| Property | |||||
|---|---|---|---|---|---|
| box-reflect | 4.0 -webkit- | 79.0 -webkit- | Not supported | 4.0 -webkit- | 15.0 -webkit- |
Ici, nous voulons le reflet sous l'image :
img {
-webkit-box-reflect: below;
} Essayez-le vous-même →
<!DOCTYPE html>
<html>
<head>
<style>
img {
-webkit-box-reflect: below;
}
</style>
</head>
<body>
<h1>CSS Image Reflection</h1>
<p>Show the reflection below the image:</p>
<img src="img_tree.png">
</body>
</html>
Ici, nous voulons le reflet à droite de l'image :
img {
-webkit-box-reflect: right;
} Essayez-le vous-même →
<!DOCTYPE html>
<html>
<head>
<style>
img {
-webkit-box-reflect: right;
}
</style>
</head>
<body>
<h1>CSS Image Reflection</h1>
<p>Show the reflection to the right of the image:</p>
<img src="img_tree.png">
</body>
</html>
Pour spécifier l'écart entre l'image et le reflet, ajoutez la taille du écart avec la propriété box-reflect.
Ici, nous voulons le reflet sous l'image, avec un décalage de 20 px :
img {
-webkit-box-reflect: below 20px;
} Essayez-le vous-même →
<!DOCTYPE html>
<html>
<head>
<style>
img {
-webkit-box-reflect: below 20px;
}
</style>
</head>
<body>
<h1>CSS Image Reflection</h1>
<p>Show the reflection below the image, with a 20 pixels offset:</p>
<img src="img_tree.png">
</body>
</html>
Nous pouvons également créer un effet de fondu sur le reflet.
Créez un effet de fondu sur le reflet :
img {
-webkit-box-reflect: below 0px linear-gradient(to bottom, rgba(0,0,0,0.0),
rgba(0,0,0,0.4));
} Essayez-le vous-même →
<!DOCTYPE html>
<html>
<head>
<style>
img {
-webkit-box-reflect: below 0px linear-gradient(to bottom, rgba(0,0,0,0.0), rgba(0,0,0,0.4));
}
</style>
</head>
<body>
<h1>CSS Image Reflection</h1>
<p>Show the reflection with gradient (to make a fade-out effect):</p>
<img src="img_tree.png">
</body>
</html>