Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Image filter affects parent element

In a gallery, I want to mark some users as "gone" by applying a red cross over the thumbnail. This code works fine:

<style>
    div.former {
        position: relative;
        width: 200px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        background-color: #f00;
    }

    div.former::before,
    div.former::after {
        position: absolute;
        content: '';
        width: 100%;
        height: 15px; /* cross thickness */
        background-color: red;
        opacity: 0.8;
    }

    div.former::before {
        transform: rotate(45deg);
    }

    div.former::after {
        transform: rotate(-45deg);
    }

   
</style>
<div class="former">
    <img src="adam.jpg">
</div>

But when I apply a filter to the image

then one of the bars disappears

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

div.former img {
    filter: grayscale(0.9);
}

Tested it with Firefox & Chrome, both showed this behaviour. I tried with setting the height of the container also, but that had no effect. So how can I make the bar visible?

>Solution :

You just need to add an z-index for the before and after elements since it is appearing behind the image.

div.former::before,
div.former::after {
    z-index: 1;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading