您好,我正在尝试创建悬停效果,因此当某人悬停在带有LI元素的图片上时,此图片保持全透明状态,但oitehr LI元素略有淡化。我知道这可以做到,但目前我的代码正在使一切淡出。CSS淡出其他
请在我的代码下找到一个小提琴。
任何帮助都很赞赏。
.imageWrapper {
position: relative;
z-index: 5;
}
.imageWrapper:after {
content: " ";
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
display: block;
z-index: 10;
transition: background 0.3s linear;
}
.cpClientIcon {
/*
.cpImageWithTitle {
.title {
@include opacity(0);
transition:opacity 0.3s linear;
}
}
*/
}
.cpClientIcon:hover .imageWrapper:after, .cpClientIcon:focus .imageWrapper:after, .cpClientIcon:active .imageWrapper:after {
background: red;
}
.cpClientIcon:hover .imageWrapper:hover, .cpClientIcon:hover .imageWrapper:focus, .cpClientIcon:hover .imageWrapper:active, .cpClientIcon:focus .imageWrapper:hover, .cpClientIcon:focus .imageWrapper:focus, .cpClientIcon:focus .imageWrapper:active, .cpClientIcon:active .imageWrapper:hover, .cpClientIcon:active .imageWrapper:focus, .cpClientIcon:active .imageWrapper:active {
/*
.title {
@include opacity(1);
}
*/
}
.cpClientIcon:hover .imageWrapper:hover .imageWrapper:after, .cpClientIcon:hover .imageWrapper:focus .imageWrapper:after, .cpClientIcon:hover .imageWrapper:active .imageWrapper:after, .cpClientIcon:focus .imageWrapper:hover .imageWrapper:after, .cpClientIcon:focus .imageWrapper:focus .imageWrapper:after, .cpClientIcon:focus .imageWrapper:active .imageWrapper:after, .cpClientIcon:active .imageWrapper:hover .imageWrapper:after, .cpClientIcon:active .imageWrapper:focus .imageWrapper:after, .cpClientIcon:active .imageWrapper:active .imageWrapper:after {
background: transparent;
}
/* Clients Page */
.cpClientIcon {
background: #fff;
}
.cpClientIcon.ClientIcon {
width: 100%;
}
.cpClientIcon.ClientIcon ul li {
width: 25%;
display: inline-block;
padding: 0;
margin: 0;
float: left;
}
.cpClientIcon.ClientIcon ul li.imageWrapper {
position: relative;
}
.cpClientIcon.ClientIcon ul li.imageWrapper span {
position: absolute;
bottom: 0;
opacity: 0;
transform: translate(-50%, 0);
left: 50%;
background: rgba(0, 0, 0, 0.8);
color: #fff;
width: 100%;
text-align: center;
padding: 1em 0;
transition: all 0.5s ease;
}
.cpClientIcon.ClientIcon ul li.imageWrapper:hover span {
opacity: 1;
}
.cpClientIcon.ClientIcon ul li img {
width: 100%;
height: auto;
}
https://jsfiddle.net/dfLk3gy5/
你可以设置一个悬停父元素和使用它对于看起来像这样的孩子.parent:hover .child {styles;} ...你不能通过悬停儿童元素来影响兄弟姐妹或父母 –