Instead of applying the background image to the parent div (I've named it .headingWrapper
in the below snippet), why don't you make use of pseudo-elements (::before
or ::after
)?
Below, I add an image to the before
pseudo-element, then hovering changes the image in some way (I've simply scaled the image, but other styling is possible)
.headingWrapper::before {
content: "";
background-image: url("https://cataas.com/cat");
height: 100vh;
width: 100vw;
position: absolute;
z-index: -1;
transition: transform 1.2s ease-in-out;
}
.headingWrapper:hover::before {
transform: scale(1.2);
}
<div class="headingWrapper">
<!-- want to use transform on this image -->
<h1>Hello, World!</h1>
<!-- without interrupt this -->
</div>