CSS3 Text Gradients not working?

后端 未结 4 891
天命终不由人
天命终不由人 2021-01-29 09:15

I am trying to apply pure CSS3 Gradients (no images, etc.) on some text but the text remains un-changed.

My current code is:





        
相关标签:
4条回答
  • 2021-01-29 09:37

    I was able to produce gradient text in Chrome using:

    h1 {
      font-size: 72px;
      background: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#333));
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }
    
    0 讨论(0)
  • 2021-01-29 09:41

    That will only work for webkit users. To support all browsers you'll need at least:

    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#cccccc', endColorstr='#000000'); /* for IE */
    background: -webkit-gradient(linear, left top, left bottom, from(#ccc), to(#000)); /* for webkit browsers */
    background: -moz-linear-gradient(top,  #ccc,  #000); /* for firefox 3.6+ */ 
    

    Change the color values to the values of your need.

    Edit: As @Lokase said: you can also use the generator which he linked in his/her comment.

    0 讨论(0)
  • 2021-01-29 09:43

    I would recommend this site, this will work for all modern browsers

    background-image: linear-gradient(bottom, rgb(93,245,172) 22%, rgb(121,255,207) 61%, rgb(158,255,249) 81%);
    background-image: -o-linear-gradient(bottom, rgb(93,245,172) 22%, rgb(121,255,207) 61%, rgb(158,255,249) 81%);
    background-image: -moz-linear-gradient(bottom, rgb(93,245,172) 22%, rgb(121,255,207) 61%, rgb(158,255,249) 81%);
    background-image: -webkit-linear-gradient(bottom, rgb(93,245,172) 22%, rgb(121,255,207) 61%, rgb(158,255,249) 81%);
    background-image: -ms-linear-gradient(bottom, rgb(93,245,172) 22%, rgb(121,255,207) 61%, rgb(158,255,249) 81%);
    
    background-image: -webkit-gradient(
        linear,
        left bottom,
        left top,
        color-stop(0.22, rgb(93,245,172)),
        color-stop(0.61, rgb(121,255,207)),
        color-stop(0.81, rgb(158,255,249))
    );
    

    Also try using css3pie, it allows you to add some code that makes it work in IE browsers.

    0 讨论(0)
  • 2021-01-29 09:43

    I recommend you to use -prefix-free if you are using lots of CSS3. This allows you to skip all browser prefixes, and the library will add all necessary prefixes at run time.

    Your style would look like this if you use it:

    .gradient {
            mask-image: gradient(linear, left top, left bottom, color-stop(0%,rgba(252,255,244,1)), color-stop(100%,rgba(233,233,206,1)));
        }
    
    0 讨论(0)
提交回复
热议问题