backface-visibility
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2022.
Die backface-visibility
CSS Eigenschaft legt fest, ob die Rückseite eines Elements sichtbar ist, wenn sie dem Benutzer zugewandt ist.
Probieren Sie es aus
backface-visibility: visible;
backface-visibility: hidden;
<section class="default-example" id="default-example">
<div id="example-element">
<div class="face front">1</div>
<div class="face back">2</div>
<div class="face right">3</div>
<div class="face bottom">6</div>
</div>
</section>
#default-example {
background: linear-gradient(skyblue, khaki);
}
#example-element {
width: 100px;
height: 100px;
perspective: 550px;
perspective-origin: 220% 220%;
transform-style: preserve-3d;
}
.face {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
position: absolute;
backface-visibility: inherit;
background: rgba(0, 0, 0, 0.4);
font-size: 60px;
color: white;
}
.front {
transform: translateZ(50px);
}
.back {
background: rgb(230, 0, 0);
color: white;
transform: rotateY(180deg) translateZ(50px);
}
.right {
background: rgba(0, 0, 0, 0.6);
transform: rotateY(90deg) translateZ(50px);
}
.bottom {
background: rgba(0, 0, 0, 0.6);
transform: rotateX(-90deg) translateZ(50px);
}
Die Rückseite eines Elements ist ein Spiegelbild seiner Vorderseite. Obwohl sie in 2D unsichtbar ist, kann die Rückseite sichtbar werden, wenn durch eine Transformation das Element im 3D-Raum rotiert wird. (Diese Eigenschaft hat keinen Einfluss auf 2D-Transformationen, die keine Perspektive haben.)
Syntax
/* Keyword values */
backface-visibility: visible;
backface-visibility: hidden;
/* Global values */
backface-visibility: inherit;
backface-visibility: initial;
backface-visibility: revert;
backface-visibility: revert-layer;
backface-visibility: unset;
Die backface-visibility
Eigenschaft wird als eines der unten aufgeführten Schlüsselwörter angegeben.
Werte
visible
-
Die Rückseite ist sichtbar, wenn sie dem Benutzer zugewandt ist.
-
Die Rückseite ist verborgen, was das Element effektiv unsichtbar macht, wenn es vom Benutzer abgewandt ist.
Formale Definition
Anfangswert | visible |
---|---|
Anwendbar auf | transformierbare Elemente |
Vererbt | Nein |
Berechneter Wert | wie angegeben |
Animationstyp | diskret |
Formale Syntax
backface-visibility =
visible |
hidden
Beispiele
Würfel mit transparenten und undurchsichtigen Flächen
Dieses Beispiel zeigt einen Würfel mit transparenten Flächen und einen mit undurchsichtigen Flächen.
HTML
<table>
<tr>
<th><code>backface-visibility: visible;</code></th>
<th><code>backface-visibility: hidden;</code></th>
</tr>
<tr>
<td>
<div class="container">
<div class="cube show-bf">
<div class="face front">1</div>
<div class="face back">2</div>
<div class="face right">3</div>
<div class="face left">4</div>
<div class="face top">5</div>
<div class="face bottom">6</div>
</div>
</div>
<p>
Since all faces are partially transparent, the back faces (2, 4, 5) are
visible through the front faces (1, 3, 6).
</p>
</td>
<td>
<div class="container">
<div class="cube hide-bf">
<div class="face front">1</div>
<div class="face back">2</div>
<div class="face right">3</div>
<div class="face left">4</div>
<div class="face top">5</div>
<div class="face bottom">6</div>
</div>
</div>
<p>The three back faces (2, 4, 5) are hidden.</p>
</td>
</tr>
</table>
CSS
/* Classes that will show or hide the
three back faces of the "cube" */
.show-bf div {
backface-visibility: visible;
}
.hide-bf div {
backface-visibility: hidden;
}
/* Define the container div, the cube div, and a generic face */
.container {
width: 150px;
height: 150px;
margin: 75px 0 0 75px;
border: none;
}
.cube {
width: 100%;
height: 100%;
perspective: 550px;
perspective-origin: 150% 150%;
transform-style: preserve-3d;
}
.face {
display: block;
position: absolute;
width: 100px;
height: 100px;
border: none;
line-height: 100px;
font-family: sans-serif;
font-size: 60px;
color: white;
text-align: center;
}
/* Define each face based on direction */
.front {
background: rgb(0 0 0 / 30%);
transform: translateZ(50px);
}
.back {
background: rgb(0 255 0 / 100%);
color: black;
transform: rotateY(180deg) translateZ(50px);
}
.right {
background: rgb(196 0 0 / 70%);
transform: rotateY(90deg) translateZ(50px);
}
.left {
background: rgb(0 0 196 / 70%);
transform: rotateY(-90deg) translateZ(50px);
}
.top {
background: rgb(196 196 0 / 70%);
transform: rotateX(90deg) translateZ(50px);
}
.bottom {
background: rgb(196 0 196 / 70%);
transform: rotateX(-90deg) translateZ(50px);
}
/* Make the table a little nicer */
th,
p,
td {
background-color: #eeeeee;
margin: 0px;
padding: 6px;
font-family: sans-serif;
text-align: left;
}
Ergebnis
Spezifikationen
Specification |
---|
CSS Transforms Module Level 2 # backface-visibility-property |
Browser-Kompatibilität
BCD tables only load in the browser