I am currently working on an on-boarding design similar to Medium's, where text is centered within a box with a black overlay and a background image.
https://i.sstatic.net/dUt0I.png
However, I am facing difficulty in preventing the text inside the div with the background image from being affected by the opacity of the overlay.
<div class="blackBackground">
<div class="topicImage opacityFilter" style="background-image: url(https://images.unsplash.com/photo-1444401045234-4a2ab1f645c0?ixlib=rb-0.3.5&q=80&fm=jp&crop=entropy&s=4372cb6539c799269e343dd9456b7eb3);">
<p class="text-inside-image">Fashion</p>
</div>
</div>
Here is my CSS:
.blackBackground {
background-color: black;
z-index: -1;
}
.opacityFilter {
opacity: 0.8;
position: relative;
}
.margin-bottom-negsix {
margin-bottom: -6px !important;
}
.topicImage {
padding-bottom: 75%;
background-position: 50% 50%;
background-repeat: no-repeat;
background-size: cover;
margin: 0 auto;
position: relative !important;
height:150px;
background-color: rgba(0, 0, 0, 0.8) !important;
}
.text-inside-image {
position: absolute;
top: 20%;
left: 35%;
color: white;
font-size: 24px;
font-weight: 500;
z-index: 1;
}
I have tried various solutions such as CSS - Opaque text on low opacity div? and How to keep text opacity 100 when its parent container is having opacity of 50
Despite these efforts, I have not been successful in resolving the issue.
You can view my progress on JSFiddle here: https://jsfiddle.net/RohitTigga/akz5zng7/1/
Can anyone help me understand why this is happening and provide guidance on how to fix it?