Home  >  Article  >  Web Front-end  >  How to implement text gradient in css3? Three ways to implement text gradient in css3 (code)

How to implement text gradient in css3? Three ways to implement text gradient in css3 (code)

不言
不言Original
2018-08-21 10:33:3146287browse

The content of this article is about how to implement text gradient in CSS3? The three methods (codes) for realizing text gradient in CSS3 have certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

During the development process, UI designers often design some design drawings with gradient text and give them to us programmers, and most of us programmers sigh silently. However, the birth of CSS3 has solved many problems in the front-end development process, such as animation, masking, etc.

1. What we want to achieve today is to use pure CSS to implement gradient text. Here is the preview picture:

How to implement text gradient in css3? Three ways to implement text gradient in css3 (code)

How to implement text gradient in css3? Three ways to implement text gradient in css3 (code)

How to implement text gradient in css3? Three ways to implement text gradient in css3 (code)

2. Basic style:

.gradient-text{
              text-align: left;
              text-indent:30px;
              line-height: 50px;
              font-size:40px;
              font-weight:bolder; 
              position: relative; 
              }

3. The first method , use background-cli, text-fill-color:

.gradient-text-one{  
    background-image:-webkit-linear-gradient(bottom,red,#fd8403,yellow); 
    -webkit-background-clip:text; 
    -webkit-text-fill-color:transparent; 
}

4. The second method, use mask-image:

.gradient-text-two{
   color:red;
}
.gradient-text-two[data-content]::after{
    content:attr(data-content);
    display: block;
    position:absolute;
    color:yellow;
    left:0;
    top:0;
    z-index:2;
    -webkit-mask-image:-webkit-gradient(linear, 0 0, 0 bottom, from(yellow), to(rgba(0, 0, 255, 0)));
}

5. The third method, use linearGradient, fill:

.gradient-text-three{
    fill:url(#SVGID_1_);
    font-size:40px;
    font-weight:bolder;
}

    
        
            
            
            
        
    
    花信年华

6. The entire code of this DEMO:




    
    
    CSS3渐变字体
    
    
    
    


    

方法1. background-clip + text-fill-color

花样年华

方法2. mask-image

豆蔻年华

方法3. svg linearGradient

花信年华

Related recommendations:

css progress bar text gradient according to progress

DIV CSS JS implemented text color gradient (reprint)_html/css_WEB-ITnose

##css3 text gradient animation

The above is the detailed content of How to implement text gradient in css3? Three ways to implement text gradient in css3 (code). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn