图像翻转悬停只是反映图像,而不是实际翻转

时间:2015-09-03 19:48:06

标签: html css image hover flip

该网站是3peak.us,我目前正试图在页面上均匀显示3个图像翻转div。我也希望它能够做出回应。

我已经尝试将它们全部放在一个宽度为100%的div中,然后将每个放入30%,但它似乎不起作用。当我将它们设为30%时,它们将成为实际图像div的30%,而不是整个页面。

这是div的css编码。

.threeflips {
  width: 100%;
}

.flip-container {
  -webkit-perspective: 1000;
  -moz-perspective: 1000;
  -o-perspective: 1000;
  perspective: 1000;
width: 30%;
float: left;
}

.flip-container:hover .flipper,  
  .flip-container.hover .flipper {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
    -o-transform: rotateY(180deg);
transform: rotateY(180deg);
}

.flip-container, .front, .back {
width: 400px;
height: 400px;
}

.flipper {
-webkit-transition: 0.6s;
-webkit-transform-style: preserve-3d;

-moz-transition: 0.6s;
-moz-transform-style: preserve-3d;

  -o-transition: 0.6s;
-o-transform-style: preserve-3d;

transition: 0.6s;
transform-style: preserve-3d;

position: relative;
}

.front, .back {
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
  -o-backface-visibility: hidden;
backface-visibility: hidden;

position: absolute;
top: 0;
left: 0;
}

.front {
background: url(https://www.3peaks.us/wp-content/uploads/2015/09/1front.jpg) 0 0 no-repeat;
background-size: 100% 100%;
z-index: 2;
}

.back {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
  -o-transform: rotateY(180deg);
transform: rotateY(180deg);

background: url(https://www.3peaks.us/wp-content/uploads/2015/09/1back.jpg) 0 0 no-repeat;
background-size: 100% 100%;
}









.bflip-container {
  -webkit-perspective: 1000;
  -moz-perspective: 1000;
  -o-perspective: 1000;
  perspective: 1000;
float: left;
width: 30%;
}

.bflip-container:hover .bflipper,  
  .bflip-container.hover .bflipper {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
    -o-transform: rotateY(180deg);
transform: rotateY(180deg);
}

.bflip-container, .bfront, .bback {
width: 400px;
height: 400px;
}

.bflipper {
-webkit-transition: 0.6s;
-webkit-transform-style: preserve-3d;

-moz-transition: 0.6s;
-moz-transform-style: preserve-3d;

  -o-transition: 0.6s;
-o-transform-style: preserve-3d;

transition: 0.6s;
transform-style: preserve-3d;

position: relative;
}

.bfront, .bback {
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
  -o-backface-visibility: hidden;
backface-visibility: hidden;

position: absolute;
top: 0;
left: 0;
}

.bfront {
background: url(https://www.3peaks.us/wp-content/uploads/2015/09/2front.jpg) 0 0 no-repeat;
background-size: 100% 100%;
z-index: 2;
}

.bback {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
  -o-transform: rotateY(180deg);
transform: rotateY(180deg);

background: url(https://www.3peaks.us/wp-content/uploads/2015/09/2back.jpg) 0 0 no-repeat;
background-size: 100% 100%;
}






.cflip-container {
  -webkit-perspective: 1000;
  -moz-perspective: 1000;
  -o-perspective: 1000;
  perspective: 1000;
width: 30%;
float: left;
}

.cflip-container:hover .cflipper,  
  .cflip-container.hover .cflipper {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
    -o-transform: rotateY(180deg);
transform: rotateY(180deg);
}

.cflip-container, .cfront, .cback {
width: 400px;
height: 400px;
}

.cflipper {
-webkit-transition: 0.6s;
-webkit-transform-style: preserve-3d;

-moz-transition: 0.6s;
-moz-transform-style: preserve-3d;

  -o-transition: 0.6s;
-o-transform-style: preserve-3d;

transition: 0.6s;
transform-style: preserve-3d;

position: relative;
}

.cfront, .cback {
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
  -o-backface-visibility: hidden;
backface-visibility: hidden;

position: absolute;
top: 0;
left: 0;
}

.cfront {
background: url(https://www.3peaks.us/wp-content/uploads/2015/09/3front.jpg) 0 0 no-repeat;
background-size: 100% 100%;
z-index: 2;
}

.cback {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
  -o-transform: rotateY(180deg);
transform: rotateY(180deg);

background: url(https://www.3peaks.us/wp-content/uploads/2015/09/3back.jpg) 0 0 no-repeat;
background-size: 100% 100%;
}

这是html

<div class="threeflips">
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
  <div class="flipper">
    <div class="front">
    </div>
    <div class="back">
    </div>
  </div>
</div>


<div class="bflip-container" ontouchstart="this.classList.toggle('hover');">
  <div class="bflipper">
    <div class="bfront">
    </div>
    <div class="bback">
    </div>
  </div>
</div>


<div class="cflip-container" ontouchstart="this.classList.toggle('hover');">
  <div class="cflipper">
    <div class="cfront">
    </div>
    <div class="cback">
    </div>
  </div>
</div>

一旦我将.flip-container,.front .back改为30%,它就会使所有这些都消失。所以我得到它们的唯一方法就是设置px宽度但是它们不再响应。

1 个答案:

答案 0 :(得分:0)

为什么要将.front,.back更改为30%? .front和.back应该是100%宽度,根据你的设计,.flip容器应该是30%或33.33%

.flip-container {
width: 33.33%;
height: 400px;
}
.front, .back {
width: 100%;
height: 400px;}

因此.flip容器样式与.front和.back样式分开,您的代码已根据您的简介进行了编辑,并可在 codepen here

上找到