CSS3: backface-visibility


Khóa học qua video:
Lập trình Python All Lập trình C# All SQL Server All Lập trình C All Java PHP HTML5-CSS3-JavaScript
Đăng ký Hội viên
Tất cả các video dành cho hội viên

Tổng quan

Thuộc tính backface-visibility dùng để xác định có hiển thị mặt sau của phần tử hiện thời hay không.

Giá trị mặc định: visible.

Áp dụng cho: Các phần tử có thể thay đổi hình dạng.

Tính thừa kế: Không có tính thừa kế.

Media: visible.

Giá trị được tính: Theo quy định.

Khả năng về hoạt ảnh: Không.

Thứ tự chính tắc: Thứ tự chuẩn theo văn phạm chính tắc.

Cú pháp

backface-visibility: visible;

Hoặc:

backface-visibility: hidden;

Các giá trị

· visible: hiện, mặt sau của phần tử sẽ hiện, mặt trước sẽ hiển thị theo hình thức phản chiếu (mirror).

· hidden: ẩn, mặt sau ẩn so với mặt trước.

Ví dụ

Tạo khối lập phương (cube) với giao diện trong suốt.

Phần HTML

<table>
  <tbody>
    <tr>
      <th><code>backface-visibility: visible;</code></th>
      <th><code>backface-visibility: hidden;</code></th>
    </tr>
    <tr>
      <td>
        <div class="container">
          <div class="cube showbf">
            <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>Tất cả các mặt đều trong suốt và các mặt sau visible so với các măt trước.</p>
      </td>
      <td>
        <div class="container">
          <div class="cube hidebf">
            <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>Tất cả các mặt đều trong suốt nhưng các mặt sau lại ẩn so với các mặt trước.</p>
      </td>
    </tr>
  </tbody>
</table>

Phần CSS

/* Phần CSS sử dụng backface-visibility */
.hidebf div {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.showbf div {
  backface-visibility: visible;
  -webkit-backface-visibility: visible;
}

/* Phần CSS tạo bộ chứa các thành phần của khối lập phương */
.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;
  -webkit-perspective: 300px;
  -webkit-perspective-origin: 150% 150%;
  -webkit-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;
}

/* Tạo từng mặt của khối lập phương */
.front {
  background: rgba(0, 0, 0, 0.3);
  transform: translateZ(50px);
  -webkit-transform: translateZ(50px);
}

.back {
  background: rgba(0, 255, 0, 1);
  color: black;
  transform: rotateY(180deg) translateZ(50px);
  -webkit-transform: rotateY(180deg) translateZ(50px);
}

.right {
  background: rgba(196, 0, 0, 0.7);
  transform: rotateY(90deg) translateZ(50px);
  -webkit-transform: rotateY(90deg) translateZ(50px);
}

.left {
  background: rgba(0, 0, 196, 0.7);
  transform: rotateY(-90deg) translateZ(50px);
  -webkit-transform: rotateY(-90deg) translateZ(50px);
}

.top {
  background: rgba(196, 196, 0, 0.7);
  transform: rotateX(90deg) translateZ(50px);
  -webkit-transform: rotateX(90deg) translateZ(50px)
}

.bottom {
  background: rgba(196, 0, 196, 0.7);
  transform: rotateX(-90deg) translateZ(50px);
  -webkit-transform: rotateX(-90deg) translateZ(50px);
}

/* Phần CSS tạo bố cục cho bảng chứa các khối lập phương */
th, p, td {
  background-color: #EEEEEE;
  margin: 0px;
  padding: 6px;
  font-family: sans-serif;
  text-align: left;
}



 

Khả năng tương thích trình duyệt

Desktop

Feature

Chrome

Firefox (Gecko)

Internet Explorer

Opera

Safari (WebKit)

Basic support

12 (-webkit)

10 (10) (-moz)
16 (16)

10

15 (-webkit)

(Yes) (-webkit)

Mobile

Feature

Android

Chrome for Android

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

3.0 (-webkit)

(Yes) (-webkit)

10.0 (10) (-moz)
16.0 (16)

8.1
11 (-webkit)

(Yes) (-webkit)

(Yes) (-webkit)

Xem thêm

· transform 2D

· transform 3D

· Các thuộc tính liên quan đến transform: perspectiveperspective-origintransformtransform-origintransform-style

» Tiếp: CSS: background
« Trước: CSS: azimuth
Khóa học qua video:
Lập trình Python All Lập trình C# All SQL Server All Lập trình C All Java PHP HTML5-CSS3-JavaScript
Đăng ký Hội viên
Tất cả các video dành cho hội viên
Copied !!!