I have a background image shown with partial opacity for a <section>
element (on the snippet it spreads on everything for some reason, on the browser it limits the image to the section..).
The issue is that the image also covers the inner HTML tags in the section.
I tried to use z-index: -1;
on the CSS, but then the image does not show when hovering over the inner HTML tags.
How can it be achieved?
The code
.card {
background-image: linear-gradient(to bottom right, white, lightgray);
border-radius: 10px;
-webkit-box-shadow: 4px 4px 40px 0px rgba(0, 0, 0, 1);
-moz-box-shadow: 4px 4px 40px 0px rgba(0, 0, 0, 1);
box-shadow: 4px 4px 40px 0px rgba(0, 0, 0, 1);
justify-content: center;
margin: 20px;
padding: 20px;
max-width: 80rem;
}
.card:hover {
animation: glow 1.2s infinite alternate;
}
@keyframes glow {
from {
-webkit-box-shadow: 4px 4px 40px 0px rgba(0, 0, 0, 1);
-moz-box-shadow: 4px 4px 40px 0px rgba(0, 0, 0, 1);
box-shadow: 4px 4px 40px 0px rgba(0, 0, 0, 1);
}
to {
-webkit-box-shadow: 3px 3px 30px 0px #3d6ded;
-moz-box-shadow: 3px 3px 30px 0px #3d6ded;
box-shadow: 3px 3px 30px 0px #3d6ded;
}
}
.bg-image {
background-image: url('https://cdn.pixabay.com/photo/2021/03/20/10/26/field-6109500_960_720.jpg');
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
border-radius: 10px;
opacity: 0;
transition: ease-in-out 0.6s;
}
.bg-image:hover {
opacity: 0.6;
}
<!DOCTYPE html>
<html lang="en">
<body>
<section class="card">
<div class="bg-image"></div>
<h2>
H2 heading
</h2>
<p>
This is a <strong>paragraph</strong>. I like paragraphs. Paragraphs are very nice.
</p>
</section>
</body>
</html>