I would like to have a text that switches its color at a certain point x. I have provided a sample that uses the text twice to produce the result, with the switch at 45px. Is there a way to do this in css without having the text twice? Maybe using svg?
div{
width: 400px;
height: 40px;
border: 1px solid #000;
position: relative;
}
div>span{
position: absolute;
top: 0;
left: 0;
}
div :nth-child(2){
color: blue;
clip: rect(0 200px 40px 45px);
}
div :nth-child(1){
color: red;
clip: rect(0 45px 40px 0);
}
<div>
<span>Some bicolored Text</span>
<span>Some bicolored Text</span>
</div>
Steps to add multicolor into text: Add a simple text inside the <div> tag with the required selector. Apply the linear gradient property with any colors of your choice. Apply webkit properties that will fill the text with the gradient background and declare the color property with transparent background.
To change the color of text in Word, select the text you want to modify and pick a new color from the Font Color drop-down menu on the Home tab. Each selection of text retains its own coloring. After picking the color for one selection, select another block of text and pick another color.
Select the shape or text box. On the Drawing Tools Format tab, click Text Fill > More Fill Colors. In the Colors box, either click the color you want on the Standard tab, or mix your own color on the Custom tab. Custom colors and colors on the Standard tab aren't updated if you later change the document theme.
You can use :before
and :after
pseudo classes:
div {
width: 400px;
height: 40px;
border: 1px solid #000;
position: relative;
}
div:before,
div:after {
content:attr(data-text);
}
div:after{
position: absolute;
top: 0;
left: 0;
}
div:after {
color: blue;
clip: rect(0 200px 40px 45px);
}
div:before {
color: red;
clip: rect(0 45px 40px 0);
}
<div data-text="Some bicolored Text">
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With