0

I'm trying to make certain image which rotates around when the mouse is hovering the object, If I do this rotation on the Y axis everything works fine, however when I do this on the X axis everything tends to fail like the example below.

EDIT: I'm using Chrome, and now looking further on this, Internet explorer doesn't even show the red face at all.

.card-container {
  height: 150px;
  perspective: 600;
  position: relative;
  width: 150px;
}
.card {
  height: 100%;
  position: absolute;
  transform-style: preserve-3d;
  transition: all 1s ease-in-out;
  width: 100%;
  background: green;
}
.card:hover {
  transform: rotateX(180deg);
}
.card .side {
  backface-visibility: hidden;
  height: 100%;
  position: absolute;
  width: 100%;
}
.card .back {
  transform: rotateX(180deg);
  background: red;
}
<div class="card-container">
  <div class="card">
    <div class="side"></div>
    <div class="side back"></div>
  </div>
</div>

Correct version (Y version):

.card-container {
  height: 150px;
  perspective: 600;
  position: relative;
  width: 150px;
}
.card {
  height: 100%;
  position: absolute;
  transform-style: preserve-3d;
  transition: all 1s ease-in-out;
  width: 100%;
  background: green;
}
.card:hover {
  transform: rotateY(180deg);
}
.card .side {
  backface-visibility: hidden;
  height: 100%;
  position: absolute;
  width: 100%;
}
.card .back {
  transform: rotateY(180deg);
  background: red;
}
<div class="card-container">
  <div class="card">
    <div class="side"></div>
    <div class="side back"></div>
  </div>
</div>

9
  • it seems a correct rotation along the x axis to me Commented Sep 23, 2014 at 10:08
  • The image resets to the green side when the animation is complete Commented Sep 23, 2014 at 10:09
  • 1
    This is how the transition works: if you lose the :hover state you have a transition to the initial state Commented Sep 23, 2014 at 10:10
  • 1
    @Fabrizio Then why the difference in behavior between rotateX and rotateY? Commented Sep 23, 2014 at 10:11
  • 2
    Confirmed in chrome, seems like a browser bug to me. Commented Sep 23, 2014 at 10:22

1 Answer 1

2

If you remove transform: rotateX(180deg); from .card .back it properly works also on Chrome

.card-container {
  height: 150px;
  perspective: 600;
  position: relative;
  width: 150px;
}
.card {
  height: 100%;
  position: absolute;
  transform-style: preserve-3d;
  transition: all 1s ease-in-out;
  width: 100%;
  background: green;
}
.card:hover {
  transform: rotateX(180deg);
}
.card .side {
  backface-visibility: hidden;
  height: 100%;
  position: absolute;
  width: 100%;
}
.card .back {
  background: red;
}
<div class="card-container">
  <div class="card">
    <div class="side"></div>
    <div class="side back"></div>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

Your code does the colors inverted, but I'll find a workaround for that, Thanks! i'll mark it as an awnser as soon as I am allowed to do that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.