Text with two colors

后端 未结 6 1440
醉话见心
醉话见心 2021-01-11 11:49

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. I

6条回答
  •  感情败类
    2021-01-11 12:41

    Another possible option is to use SVG. You can create multi colored text in SVG using gradients. If two adjacent gradient stops are at the same position then you will get a sharp transition between colors. If two adjacent gradient stops are at different positions then you will get a smooth transition between colors. You can have as many color stops as you want. For example...

    
        
            
                
                
            
            
                
                
                
                
            
            
                
                
            
        
        Some bicolored Text
        Some tricolored Text
        Some smooth gradient Text
    
    

    Note that in SVG, the color stops are at relative positions (e.g. 0 to 1, 0% to 100%). This could make it a little hard if you are trying to place the color stops at specific pixel locations.

    Note that in SVG, you have to manually position the text element within the svg element.

提交回复
热议问题