Why doesn't filter: contrast doesn't work?

344 views Asked by At

So I'm trying to achieve so called gooey effect with css filter blur and contrast properties. However for some reason contrast doesn't work ? Any ideas why ?

I'm pasting my HTML and CSS below.

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>

    <div class="container">
        <div class="liquid">
            <div class="left">
                
            </div>
            <div class="right">

            </div>
        </div>
    </div>
    
</body>
</html>

SCSS:

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.container {
    height: 100vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
}

.liquid {
    display: flex;
    filter: contrast(20);

    .left,
    .right {
        width: 80px;
        height: 80px;
        background-color: black;
        border-radius: 50%;
        filter: blur(10px);
    }

    .left {
        animation: anim-1 2s infinite linear;
    }

    .right {
        animation: anim-2 2s infinite linear;
    }
}

@keyframes anim-1 {
    0% {
        transform: translateX(50%);
    }
    50% {
        transform: translateX(0%);
    }
    100% {
        transform: translateX(50%);
    }
}

@keyframes anim-2 {
    0% {
        transform: translateX(-50%);
    }
    50% {
        transform: translateX(0%);
    }
    100% {
        transform: translateX(-50%);
    }
}
3

There are 3 answers

0
AudioBubble On

Try putting contrast on the same line that the blur filter is, separated by a space between properties:

.left,
.right {
  ...
  filter: blur(10px) contrast(20);
}
1
Ali Hamdan On

With contrast filter you have to use % so just define filter:contrast(20%) and it should work fine

0
Noiseymur On

Okay, I've found why. I needed to add a background color to the div which also has the contrast filter