I want to do something like this:
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>
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.
Comments