What does backface-visibility: hidden do in CSS?

0305

The backface-visibility property in CSS is used to control the visibility of the back face of an element when it is rotated in 3D space. When you set backface-visibility: hidden;, it means that the back face of the element will not be visible when the element is rotated.

Here's a brief explanation of how it works:

  • backface-visibility: visible;: The back face of the element is visible when it is rotated.
  • backface-visibility: hidden;: The back face of the element is not visible when it is rotated, effectively hiding it from view.

This property is particularly useful when creating 3D effects, such as flipping cards or other elements, where you want to ensure that the back side does not show through when the front side is facing the viewer.

Example:

.card {
  width: 200px;
  height: 300px;
  perspective: 1000px; /* Required for 3D effect */
}

.card-inner {
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s;
}

.card-inner:hover {
  transform: rotateY(180deg);
}

.card-front, .card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden; /* Hides the back face */
}

.card-back {
  transform: rotateY(180deg); /* Rotate back face */
}

In this example, when you hover over the .card, it flips to show the back face, and the back face will not be visible when it is rotated away from the viewer.

0 Comments

no data
Be the first to share your comment!