Check out this new solution:
To create an interesting text effect, try setting the background of the h1
element using linear-gradient with your desired colors for the text. Then, make the text color transparent and apply background-clip: text
to color the text accordingly. Make sure to check the compatibility across browsers.
.bg {
background: linear-gradient(175deg, #e2e2e2 50%, #435289 50%);
color: #000;
}
h1 {
color: transparent;
background: linear-gradient(175deg, #435289 50%, white 50%);
-webkit-background-clip: text;
background-clip: text;
}
<div class="bg">
<h1>
Hiii, My Name is John, I love Stackoverflow. I really don't know, how to do this, Can someone help me? If Background = Blue, Text Color = White
</h1>
</div>
</div>
Here's the original suggestion:
If you're looking for contrast instead of exact colors, consider utilizing mix-blend-mode
to dynamically adjust the text color based on the background:
.bg {
background: linear-gradient(175deg, #e2e2e2 50%, #435289 50%);
color: #000;
}
h1 {
color: #fff;
mix-blend-mode: difference;
}
<div class="bg">
<h1>
Hiii, My Name is John, I love Stackoverflow. I really don't know, how to do this, Can someone help me? If Background = Blue, Text Color = White
</h1>
</div>
</div>