Max
Max

Reputation: 477

How to use CSS 3D to display child elements perpendicular to parent element?

The desired effect is to have 2 perpendicular dom elements like a 'pop-up' book. However, the child element seems to get flattened/projected onto the parent's plane.

It seems to work if the 2 elements are siblings. However, I'm looking for a way to achieve this for parent/child elements.

<div class="container">
    <div class="parent" style="height:300px; width:300px;">
      <div class="child" style="height:100px; width:10px;">

      </div>
    </div>
</div>

.container {
  perspective: 1000;
  -moz-perspective: 1000;
  -webkit-perspective: 1000;
}

.parent {
  transform:rotateX(60deg);
  -moz-transform:rotateX(60deg);
  -webkit-transform:rotateX(60deg);
  background:grey;
}

.child {
  transform:rotateX(-30deg);
  -moz-transform:rotateX(-30deg);
  -webkit-transform:rotateX(-30deg);
  background:red;
  margin: 100px;
}

Upvotes: 0

Views: 663

Answers (2)

Max
Max

Reputation: 477

I've found the solution.

.parent {
    overflow: visible !important;
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
}

solved everything

Upvotes: 1

Venugopal
Venugopal

Reputation: 1896

I have some modifications to parent and child elements

.parent:before,
.parent:after {
 content: ".";    
 display: block;    
 height: 0;    
 overflow: hidden; 
}
.parent:after {clear: both;}

.child {
 transform:rotate(-7deg);
-moz-transform:rotate(-7deg);
-webkit-transform:rotate(-7deg);
background:red;
margin: -60px 100px 100px 100px;
}

Here you can see the fiddle click here

Upvotes: 0

Related Questions