I want to make a button with a diagonal background with two colors. In turn, the text that is inside it also has to be split diagonally in the same way as the button, that is, if it splits a letter in half, each of the parts of the letter must be a color.
Here is the CSS I have so far. As you can see, the text is not in two colors, it would have to respect the diagonal of the button's background in two colors:
.button{
background: linear-gradient(140deg, #00C9FF 35%, transparent 35%);
}
<button class="button">some long text</button>
Does anyone know how to fix this with CSS?
This could be fixed by entering the text into a tag, for example,
p
and then adding anotherlinear-gradient
to this tag.EDIT: As you have commented
@blonfu
, the-webkit-background-clip: text
and properties-webkit-text-fill-color: transparent
are what do the magic. Unfortunately, however, these are not supported for all types of browsers.The property that is going to give us the most problems is going to be
-webkit-text-fill-color
since it is not compatible withInternet Explorer
norEdge
. It will also give us problems with some versions ofFirefox
and with versions ofOpera Mini
.I have used
caniuse.com
to look at the properties compatibility:-webkit-background-clip
-webkit-text-fill-color
-webkit-linear-gradient
Also add that it is not the same that you use
-webkit-linear-gradient
that simplylinear-gradient
. You can check it by modifying it in the example and seeing that the behavior is not the same.