質問

I have some css 3D divs but im having some problems.. I want to rotate the outer div in perspective, but i don't want to rotate the inner div with it. How do I reset these styles to make the inner div flat again.

The HTML:

<section class="container" style="-webkit-perspective: 2000px; -webkit-perspective-origin-x: 0%; -webkit-perspective-origin-y: 0%;">
<div id="cube">
  <div class="bottom plutoring">
        <div class="planet pluto">
              <p> pluto </p>
        </div>
  </div>
</div>

The CSS

.container {
  width: 1000px;
  height: 900px;
  position: relative;
  margin: 0 auto 40px;
  -webkit-perspective: 1200px;
     -moz-perspective: 1200px;
       -o-perspective: 1200px;
          perspective: 1200px;
}

#cube {
  width: 100%;
  height: 100%;
  position: absolute;
  -webkit-transform-style: preserve-3d;
     -moz-transform-style: preserve-3d;
       -o-transform-style: preserve-3d;
          transform-style: preserve-3d;
}
.bottom {
     -webkit-transform: rotateX( 82deg ) rotateY( -5deg ) rotateZ( 197deg );
}

Any suggestions?

役に立ちましたか?

解決

You need 2 things:

  • enable in the parent of the planet preserve3d
  • transform the planet in the oposite way.

CSS

.bottom {
     -webkit-transform: rotateX( 82deg ) rotateY( -5deg ) rotateZ( 197deg );
    background:green;
    -webkit-transform-style: preserve-3d;
}

.planet{
    background:blue;
    display:inline-block;
    font-size: 40px;
     -webkit-transform:  rotateZ( -197deg ) rotateY( 5deg ) rotateX( -82deg ) ;
}

Note that the inverse transform is the original with the signs changed and the order reversed.

fiddle

他のヒント

my hunch is that in your code, the planet's ring needs to a child element of the planet, or a sibling of it. the ring should not be the parent of the planet if you don't want the ring's css transform to affect the planet.

have a look at this:

http://neography.com/experiment/circles/solarsystem/

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top