Computer >> 컴퓨터 >  >> 프로그래밍 >> CSS

CSS transform-style 속성으로 중첩 요소의 3D 렌더링 방식 지정하기

3D 공간에서 중첩된(nested) 요소가 어떻게 렌더링될지 지정하려면 CSS의 transform-style 속성을 사용합니다.

transform-style 속성의 주요 값

  • flat(기본값): 자식 요소가 부모의 3D 공간에 참여하지 않고 평면적으로 렌더링됩니다.
  • preserve-3d: 자식 요소가 부모의 3D 공간을 그대로 유지한 채 렌더링되어 입체적인 3D 변형 효과를 구현할 수 있습니다.

아래 예제에서는 가장 안쪽 요소(.demo3)에 transform-style: preserve-3d;를 적용하여 회전 변형 시 자식 요소들이 3D 공간을 유지하도록 설정했습니다.

예제

다음 코드를 실행하여 transform-style 속성을 직접 확인해 보세요.

<!DOCTYPE html>
<html>
   <head>
      <style>
         .demo1 {
            width: 300px;
            height: 300px;
            background-color: yellow;
         }
         .demo2 {
            width: 200px;
            height: 200px;
            background-color: orange;
         }
         .demo3 {
            width: 100px;
            height: 100px;
            background-color: blue;
            transform: rotate(10deg);
            transform-origin: 30% 40%;
            transform-style: preserve-3d;
         }
      </style>
   </head>

   <body>
      <h1>Rotation</h1>
      <div class = "demo1">Demo
         <div class = "demo2">Demo
            <div class = "demo3">
               Demo
            </div>
         </div>
      </div>
   </body>
</html>