Reputation: 65
Hello I am trying to create a hover effect so when someone hovers over an image withing an LI element this image stays full opacity but the oitehr LI elements fade out slightly. I know this can be done but currently my code is making everything fade out.
Please find a fiddle below my code.
Any help is appreciated greatly.
.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/
Upvotes: 1
Views: 2113
Reputation: 106008
you could use the mix-blend-mode too :
li a {
background: rgba(255, 255, 255, 0.5);
display: inline-block;
width:100%;
}
li * {
mix-blend-mode: soft-light;
}
li:hover * {
mix-blend-mode: unset;
}
li {display:inline-block;width:20%;}
img {max-width:100%;}
<div class="stPage st">
<div class="gpClientIcons">
<div class="cpClientIcon ClientIcon">
<ul>
<li class="imageWrapper"> <a href="/work/angostura-1919">
<img src="http://good.dev.good-creative.com/sites/default/files/styles/client_logo/public/CLIENT_LOGOS_WHITE_BG_24_ANGOSTURA.png?itok=TxAkk1y-"/>
</a>
<a href="/work/angostura-1919"><span>View Case Study</span></a>
</li>
<li class="imageWrapper"> <a href="/work/fyne-ales">
<img src="http://good.dev.good-creative.com/sites/default/files/styles/client_logo/public/03_1.png?itok=NRCjw1SJ"/>
</a>
<a href="/work/fyne-ales"><span>View Case Study</span></a>
</li>
<li class="imageWrapper"> <a href="/work/glengoyne">
<img src="http://good.dev.good-creative.com/sites/default/files/styles/client_logo/public/01_.png?itok=ib3J3BkM"/>
</a>
<a href="/work/glengoyne"><span>View Case Study</span></a>
</li>
<li class="imageWrapper"> <a href="/work/okells">
<img src="http://good.dev.good-creative.com/sites/default/files/styles/client_logo/public/01_.png?itok=ib3J3BkM"/>
</a>
<a href="/work/okells"><span>View Case Study</span></a>
</li>
<li class="imageWrapper"> <a href="/work/rrspink-sons">
<img src="http://good.dev.good-creative.com/sites/default/files/styles/client_logo/public/03_1.png?itok=NRCjw1SJ">
</a>
<a href="/work/rrspink-sons"><span>View Case Study</span></a>
</li>
<li class="imageWrapper"> <a href="/work/tamdhu">
<img src="http://good.dev.good-creative.com/sites/default/files/styles/client_logo/public/01_.png?itok=ib3J3BkM">
</a>
<a href="/work/tamdhu"><span>View Case Study</span></a>
</li>
</ul>
</div>
</div>
</div>
it can be done for any element inside li or only to img : https://jsfiddle.net/dfLk3gy5/1/
Upvotes: 0
Reputation: 1397
Set your hover rule for the UL
to set all child LI
elements to the desired faded out opacity, then set a hover rule for the LI
to set opacity back to fully opaque:
ul:hover li {
opacity: 0.5;
}
ul:hover li:hover {
opacity: 1;
}
Example: https://jsfiddle.net/kgow697h/
Upvotes: 5