Internet Explorer中的翻转效果

时间:2016-05-13 10:21:04

标签: html css css3 flip

我有一个代码可以翻转到div。它在Firefox和Chrome中运行良好,但在IE中,当卡片翻转时,它显示正面倒置而不是显示背面。

这是代码:

body {
  background: #eee;
}

.card{
  width: 300px;
  height: 300px;
}

.content {
  width: 300px;
  height: 300px;
  perspective: 500px;
  box-shadow: 0 0 15px rgba(0,0,0,0.1);
  transition: transform 1s;
  transform-style: preserve-3d;
}

.card:hover .content {
  transform: rotateX( 180deg ) ;
  transition: transform 0.5s;
}

.front,
.back {
  position: absolute;
  height: 100%;
  width: 100%;
  background: white;
  line-height: 300px;
  color: #03446A;
  text-align: center;
  font-size: 60px;
  border-radius: 5px;
  backface-visibility: hidden;
  }

.back {
  background: #03446A;
  color: white;
  transform: rotateX( 180deg );
}
<div class="card">
   <div class="content">
     <div class="front">
        Front
     </div>
     <div class="back">
        Back!
     </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:3)

正如Shaggy评论的那样,IE不支持preserve-3d。它也缺乏对背面可见性的支持:隐藏;

因此,您无法旋转容器,您必须单独旋转元素。

你需要调整能见度(转换时间的一半,你希望它在旋转中间发生。

这是结果,适用于现代浏览器以及IE

body {
  background: #eee;
}

.card{
  width: 300px;
  height: 300px;
}

.content {
  width: 300px;
  height: 300px;
  perspective: 500px;
  box-shadow: 0 0 15px rgba(0,0,0,0.1);
  transition: transform 1s;
  transform-style: preserve-3d;
}

.card:hover .content {
}

.front,
.back {
  position: absolute;
  height: 100%;
  width: 100%;
  background: white;
  line-height: 300px;
  color: #03446A;
  text-align: center;
  font-size: 60px;
  border-radius: 5px;
  backface-visibility: hidden;
  }


.front {
  transition: visibility 0.5s, transform 1s;
}

.card:hover .front {
  visibility: hidden;
  transform: rotateX(180deg);
}

.back {
  background: #03446A;
  color: white;
  transform: rotateX( -180deg );
  transition: visibility 0.5s, transform 1s;
}

.card:hover .back {
  transform: rotateX(0deg);
  
}
<div class="card">
   <div class="content">
     <div class="front">
        Front
     </div>
     <div class="back">
        Back!
     </div>
  </div>
</div>