css3 text-fill-color屬性

text-fill-color是什麼意思呢?單單從字面上來看就是「文本填充顏色」,不過它實際也是設置對象中文字的填充顏色,和color的效果很類似。若是同時設置text-fill-color和color兩個屬性,則text-fill-color會覆蓋掉color的值。css

因爲text-fill-color是css3的新屬性,一說到css3新屬性,你們確定就會問兼容效果如何呢??嘿嘿,只能絕不留情的說,兼容性不好呀,,只適用於webkit內核的瀏覽器有效果。。很惋惜啊!!不過它雖然兼容性差,可是卻能夠製做很炫酷的文字效果,好比說流光文字,鏤空文字等等。html

製做流光文字,單單使用text-fill-color但是不行呀,還須要結合css3的animation來實現動畫效果.下面直接上代碼:css3

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6     <style>
 7         *{margin: 0;padding: 0;}
 8         ._borderWrap{
 9             width: 180px;
10             height: 150px;
11             position: absolute;
12             left: 23%;
13             top: 25%;
14         }
15         ._border{
16             line-height: 145px;
17             text-align: center;
18             font-size: 40px;
19             font-weight: bolder;
20             -webkit-text-fill-color: transparent;
21             background-image:  -webkit-linear-gradient(left,#129835,#ece648 25%,#129835 50%,#F9E92B 75%,rgb(40, 150, 38));
22             background-size: 200%,100%;
23             -webkit-background-clip: text;
24             -webkit-animation: word 5s linear infinite ;
25         }
26         @keyframes word {
27             0%{background-position: 0 0}
28             100%{background-position: -100% 0}
29         }
30 
31     </style>
32 </head>
33 <body>
34         <div class="_borderWrap">
35             <div class="_border">你的名字</div>
36         </div>
37 </body>
38 </html>

效果圖:web

「你的名字」就是製做的流光文字,只不過截圖是靜態的,想看動態效果須要本身運行代碼喲!瀏覽器

 

注意,製做流光文字有幾個要點:text-fill-color通常設置爲transparent(透明色),而後利用background-image和漸變顏色來設置文字的背景色,利用background-clip來實現文字的截取,再利用background-size設置擴大背景,已使運用animation的時候能達到動畫的效果等。動畫

相關文章
相關標籤/搜索