How do I use a pseduo class to "mix-blend-mode" an SVG's fill color?

PSU Change

I want to do something like this: enter image description here

As you can see, wherever the circle is, the font changes color to black. As soon as the circle leaves, the text returns back to white.

However, instead of using text, I want to do it with SVG. When I hover over my container, I want the expanding pseudo class to make the arrow white only where it intersects (at the end of the animation, the entire arrow would be white since the black pseudo class expands the full container). I have tried the following (added to all my elements) but it does not work:

isolation: isolated;
mix-blend-mode: difference; 

Here is my code, thanks in advance:

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

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

.svg-container,
svg,
.svg-container::before,
path {
    isolation: isolated;
    mix-blend-mode: difference;
}

.svg-container {
    border-radius: 50%;
    position: relative;
    border: 1px solid black;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    cursor: pointer;
}

.svg-container::before {
    content: "";
    background-color: none;
    position: absolute;
    border-radius: 50%;
    width: 0%;
    z-index: -4;
    height: 0%;
    transition: all 0.5s ease-in-out;
}

.svg-container:hover::before {
    height: 100%;
    width: 100%;
    background-color: black;
    transition: all 0.5s ease-in-out;
}

.svg-actual {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
}

path {
    transition: all 0.5s ease-in-out;
}
.svg-container:hover path {
    /* fill: white; */
    transition: all 0.5s ease-in-out;
}

.text {
    position: absolute;
    font-size: 0.6rem;
}
    
    <div class="formatting">
        <div class="svg-container">
            <div class="svg-actual">
                <svg width="27" height="15" viewBox="0 0 280 184" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path id="arrow" d="M259.585 97.2345L180.703 176.117L187.96 183.375L279.22 92.115L187.955 0.850169L180.707 8.09801L259.577 86.9878L0.129355 86.9758V97.2345L259.585 97.2345Z" fill="#010002"/>
                </svg>
            </div>
        </div>
    </div>

Michael Mullany

The problem is not the pseudo elements.

You have two problems here. The first problem is that you're using transition: all - so the mix-blend-mode is being transitioned in, so you can't see it. You need to specify transition applying to just width/height.

The second problem is that you're trying to blend black with black - that doesn't work - it just gives you black. If I tweak your example to match your initial image example (black background, white foreground, black arrow) it works just fine.

Here is a tweaked and exaggerated version to show you everything working.

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

.formatting {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    transform: scale(300%);
    background: black;
}

.svg-container {
    border-radius: 50%;
    position: relative;
    border: 1px solid white;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    cursor: pointer;
}

.svg-container::before {
    content: "";
    background-color: none;
    position: absolute;
    border-radius: 50%;
    width: 0%;
    height: 0%;
    transition: height 5s ease-in-out, width 5s ease-in-out;
}

.svg-container:hover::before {
    height: 100%;
    width: 100%;
    background-color: white;
    transition: height 5s ease-in-out, width 5s ease-in-out;

}

.svg-actual {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
    mix-blend-mode: difference;
}

path {
    transition: height 5s ease-in-out, width 5s ease-in-out;
}
.svg-container:hover path {
    /* fill: white; */
    transition: height 5s ease-in-out, width 5s ease-in-out;
}

.text {
    position: absolute;
    font-size: 0.6rem;
}
   <div class="formatting">
        <div class="svg-container">
            <div class="svg-actual">
                <svg width="27" height="15" viewBox="0 0 280 184" fill="none" xmlns="http://www.w3.org/2000/svg" id="#svg-element" color-interpolation="sRGB">
                    <path id="arrow" d="M259.585 97.2345L180.703 176.117L187.96 183.375L279.22 92.115L187.955 0.850169L180.707 8.09801L259.577 86.9878L0.129355 86.9758V97.2345L259.585 97.2345Z" stroke="white" stroke-width="20"/>
                </svg>
            </div>
        </div>
    </div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to use mix-blend-mode to change text color on an animated background

mix-blend-mode: How do I prevent a part of the circle from blending with the other circle

How to use mix-blend-mode on focus outline based on background?

How to decide the color of the text when using mix-blend-mode in CSS?

How to fix Safari mix-blend-mode: color-dodge bug?

Mix-blend-mode doesn't work if I use "transform" on the parent div

change text color with mix-blend-mode when divs are overlapping

How to hack unsupported mix-blend-mode CSS property?

How to apply mix-blend-mode while keeping text opaque?

How to get "mix-blend-mode" to work in this code

how do i set fill color of a svg circle with the help of thymeleaf

Mix-blend-mode: weird (temp) black background during SVG animation on android

CSS: mix-blend-mode = color-dodge not working in Chrome but okay in Firefox

Using `backdrop-filter: blur` with `mix-blend-mode`, the color of text doesn’t show correctly

Using mix-blend-mode to knock out a shape from it's parent, while keeping sibling text normal

How do I use fill color for negative values in spider chart?

Why does css mix-blend-mode: color; cover all colors except white instead of all colors except white and black?

Mix blend mode in reversing colors

Mix-Blend-Mode Difference

How do I let a user click a color to become a function that changes the fill of an svg object on click

How do I fill the current selection with color?

How do I color fill this EMA Chart

How To Use PHP/MySQL To Manage Fill Color of SVG?

css mix-blend-mode and masks

Testing of CSS "mix-blend-mode"

Applying mix-blend-mode with a grayscale

Mix-blend-mode: Multiply Bug in Firefox

CSS Mix-Blend-Mode on pseudo element

mix-blend-mode doesn't work?