我在div Applicative
内的按钮上添加了css悬停效果。其中还有一个main-container
div,里面有一个background
div。问题是每次都有一个背景图像,悬停效果没有显示,但如果我删除背景图像,效果是可见的。我该如何解决? demo
layer
.background {
position: relative;
}
.background img{
max-width:100%;
max-height:800px;
}
.layer {
background-color: rgba(248, 247, 216, 0.7);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.btn {
border: none;
font-family: inherit;
font-size: inherit;
color: inherit;
background: none;
cursor: pointer;
padding: 25px 80px;
display: inline-block;
margin: 15px 30px;
text-transform: uppercase;
letter-spacing: 1px;
font-weight: 700;
outline: none;
position: relative;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
}
.btn:after {
content: '';
position: absolute;
z-index: -1;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
}
.btn:before {
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
position: relative;
-webkit-font-smoothing: antialiased;
}
/* Button 1 */
.btn-1 {
border: 3px solid #fff;
color: #fff;
}
.btn-1f {
overflow: hidden;
}
.btn-1f:after {
width: 101%;
height: 0;
top: 50%;
left: 50%;
background: #000;
opacity: 0;
-webkit-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
}
.btn-1f:hover,
.btn-1f:active {
color: #0e83cd;
}
.btn-1f:hover:after {
height: 75%;
opacity: 1;
}
.btn-1f:active:after {
height: 130%;
opacity: 1;
}
.background {
position: relative;
width: inherit;
height:inherit;
background-image: url("http://www.wallpapereast.com/static/images/nature-wallpaper-desktop-308_ySxPe7m.jpg");
}
.main-container{
width:100%;
height:745px;
position:relative;
}
.cities{position:absolute;bottom:0;}
答案 0 :(得分:1)
我检查了你的代码。 在背景上给Z-index负数,如下所示
.background {
background-image: url("http://www.wallpapereast.com/static/images/nature-wallpaper-desktop-308_ySxPe7m.jpg");
height: inherit;
position: relative;
width: inherit;
z-index: -1;
}
答案 1 :(得分:1)
你可以这样做:
e.preventDefault();
if (event.stopPropagation)
event.stopPropagation();
event.cancelBubble = true;
return false;
答案 2 :(得分:-1)
给按钮z-index
。
例如:z-index: 999;