(hard to word this issue in the title)
I have links that are images with absolute header overlays. I want the opacity of the image to change when any part of the link is hovered. My problem is that when I hover over the text that is overlayed, it omits the :hover state applied to the image.
.galleryItem img {
width: 100%;
height: 100%;
object-fit: contain;
border-radius: 10px;
filter: opacity(.7);
transition: .3s;
}
.galleryItem a,
h4 {
color: #f5f9e9;
text-decoration: none;
}
.galleryItem img:hover {
filter: opacity(1);
}
.galleryItem h4 {
text-align: center;
position: absolute;
top: 41%;
left: 50%;
font-size: 1.3em;
transform: translate(-50%, -50%);
vertical-align: middle;
z-index: 10;
text-shadow: 0px 0px 10px black;
}
<div class="galleryItem">
<a href="#">
<h4>The Combinator</h4>
<img src="img/fwaz.png">
</a>
</div>
*I DO NOT want the opacity of the h4 tag to change at all. But again, I do need hovering the h3 to maintain the same changes I’ve applied to hovering the img.
I’m not sure how to remedy this problem at all.
2
Answers
Try
pointer-events: none;
on the h4.Use hover on the parent
The hover rule should be on a parent which wraps everything.
When parent is hovered, a child element gets styled, in this case an
<img>
. Parent could begalleryItem
ora
, whichever works better.