I want to cover the child img with the color of the parent div.
Actual the child img covers the divs color.
I gave the child a lower z-index then the parent, but that changes nothing.
I can't add new html-tags and want to use css.
Have somebody a solution?
body {
display: block;
max-width: 1280px;
width: 100%;
background: black;
margin: auto;
}
main {
display: flex;
justify-content: space-around;
width: 100%;
height: 200px;
background: grey;
}
.parent {
display: flex;
justify-content: space-around;
align-items: center;
width: 23%;
height: 40%;
margin: 1%;
background-color: red;
opacity: 0.5;
position: relative;
z-index: 2;
}
.child {
position: absolute;
max-width: 100%;
max-height: 100%;
z-index: 1;
}
<main>
<div class="parent">
<img class="child" src="https://cdn.kika.de/logo/bilder/logo-logo-die-welt-und-ich100-resimage_v-tsmall169_w-448.png?version=7362">
</div>
<div class="parent">
<img class="child" src="https://cdn.kika.de/logo/bilder/logo-logo-die-welt-und-ich100-resimage_v-tsmall169_w-448.png?version=7362">
</div>
<div class="parent">
<img class="child" src="https://cdn.kika.de/logo/bilder/logo-logo-die-welt-und-ich100-resimage_v-tsmall169_w-448.png?version=7362">
</div>
<div class="parent">
<img class="child" src="https://cdn.kika.de/logo/bilder/logo-logo-die-welt-und-ich100-resimage_v-tsmall169_w-448.png?version=7362">
</div>
</main>
Try adding
:after
pseudo element as shown in below code.