我的旋转和缩放悬停效果让我认为是z-index问题。
当鼠标悬停在图像上时,它会翻转并向上扩展并显示图像的背面以及详细信息等。
问题是图像都是行,并且它们之间的边距非常小。因此,当它们缩放时,它们需要在图像的顶部重叠。此刻这种重叠在左侧和顶部都很好,但在右侧和下方的图像下方重叠......真的很奇怪!
这是我的代码 - Html
<div id="games-container">
<div class="flip-container game">
<div class="flipper">
<a href="#">
<div class="front">
<h1>Front</h1>
</div>
<div class="back">
<span class="game-title">
<h3>BACK</h3>
<span class="mob-icon"></span>
</span>
<button class="button green"><a href="#">Play Now</a></button>
<button class="blue button"><a href="#">More Info</a></button>
</div>
</a>
</div>
</div>
<div class="flip-container game">
<div class="flipper">
<a href="#">
<div class="front">
<h1>Front</h1>
</div>
<div class="back">
<span class="game-title">
<h3>BACK</h3>
<span class="mob-icon"></span>
</span>
<button class="button green"><a href="#">Play Now</a></button>
<button class="blue button"><a href="#">More Info</a></button>
</div>
</a>
</div>
</div>
<div class="flip-container game">
<div class="flipper">
<a href="#">
<div class="front">
<h1>Front</h1>
</div>
<div class="back">
<span class="game-title">
<h3>BACK</h3>
<span class="mob-icon"></span>
</span>
<button class="button green"><a href="#">Play Now</a></button>
<button class="blue button"><a href="#">More Info</a></button>
</div>
</a>
</div>
</div>
CSS -
/* make things pretty */
#games-container{
width:800px;
margin:0 auto;
}
#games-container div.game{
margin: 0 8px 15px;
float: left;
position: relative;
z-index: 1;
}
#main-container div.inner-container div.game .front img, #main-container div.inner-container div.game .back img{
width:185px;
height: 145px;
}
span.game-title {
background-color:rgba(25,25,25,0.6);
display: block;
position: absolute;
width: 100%;
top: 0px;
margin-bottom: 25px;
text-align: center;
z-index: 1;
}
span.game-title h3 {
padding: 5px;
}
.game h3, .game:hover span.game-title{
color:silver;
transition:all 0.2s ease-in;
-webkit-transition:all 0.2s ease-in;
}
.game:hover h3, .game:hover span.game-title{
color:#fff;
background-color: #0c0c0c;
}
.game a{
display: block;
}
.back > .button{
position: relative;
z-index: 1;
}
.button{
display: block;
padding: 5px 10px;
margin:5px auto;
width:70%;
clear: both;
color:#fff;
}
button a{
text-decoration: none;
color:#e5e5e5;
display: block;
transition: ease-in 0.12s;
}
button.green:hover{
background-color: #00B200;
}
button:hover a{
color:#fff;
transform:scale(1.1);
}
.back > .button.green{
margin-top: 45px;
}
button{
color:#000;
border:none;
}
button.green{
background-color: #419907;
transition:background-color 0.4s ease-in;
-webkit-transition:background-color 0.4s ease-in;
}
button.blue{
background-color:#063e9b;
transition:background-color 0.4s ease-in;
-webkit-transition:background-color 0.4s ease-in
}
/* end of making things pretty*/
/* do some flipping */
.flip-container {
perspective: 900px
transform-style: preserve-3d;
}
.flip-container:hover .back {
transform: rotateY(0deg) scale(1.3);
z-index:4;
}
.flip-container:hover .front {
transform: rotateY(180deg);
}
.flip-container, .front, .back {
width: 185px;
height: 150px;
}
/* flip speed goes here */
.flipper {
transition: 0.9s;
transform-style: preserve-3d;
position: relative;
}
/* hide back of pane during swap */
.front, .back {
backface-visibility: hidden;
transition: 0.4s;
transform-style: preserve-3d;
position: absolute;
top: 0;
left: 0;
width: 185px;
height: 145px;
}
.front {
z-index: 2;
transform: rotateY(0deg);
background-color: #333;
color: #000;
text-align: center;
}
.back {
transform: rotateY(-180deg);
background-color: #010b15;
border: solid 2px #034baf;
}
答案 0 :(得分:1)
将z-index: 2 !important;
添加到.flip-container:hover
.flip-container:hover {
transform: scale(1.25);
-webkit-transform: scale(1.25);
-ms-transform: scale(1.25);
z-index: 2 !important;
}
答案 1 :(得分:1)
由于您将第一个z-index
放在此选择器#games-container div.game
上,因此您可以将悬停选择器更改为此选项以删除重要属性:
#games-container div.game:hover {
transform: scale(1.25);
-webkit-transform: scale(1.25);
-ms-transform: scale(1.25);
z-index: 2;
}