This article mainly and everybody to share CSS3 realizes the gradient text effect, we mainly and everybody to share two kinds of methods, hoped can help everybody.
One, method one: with the Mask-image attribute
Method of the text gradient effect
The corresponding HTML code is as follows:
<H2 class= "Text-gradient" data-text= "godsend" > Heavenly beauty
The CSS code that corresponds to HTML is as follows:
. text-gradient { display:inline-block; font-family: ' Microsoft ya Black '; Font-size:10em; position:relative; } . text-gradient[data-text]::after { content:attr (data-text); Color:green; Position:absolute; left:0; Z-index:2; -webkit-mask-image:-webkit-gradient (linear, 0 0, 0 bottom, from (#ff0000), to (RGBA (0, 0, 255, 0)));}
From the CSS code can be seen, the implementation of the effect in addition to "content generation technology", mainly using the Mask-image attribute, the content is "WebKit core browser gradient".
Second, method two: Background-clip + Text-fill-color under the realization
Text gradient effect under method two
The implementation here is relatively simple, the HTML code is as follows:
<H2 class= "text-gradient" > Heavenly beauty
The CSS code that corresponds to HTML is as follows:
. text-gradient { display:inline-block; Color:green; Font-size:10em; font-family: ' Microsoft ya Black '; Background-image:-webkit-gradient (linear, 0 0, 0 bottom, from (Rgba (0, +, 0, 1)), to (Rgba (Wuyi, Wuyi, 1)); -webkit-background-clip:text; -webkit-text-fill-color:transparent;};
The key useful in CSS code is actually the last three lines:
Background-image:-webkit-gradient (linear, 0 0, 0 bottom, from (Rgba (0, +, 0, 1)), to (Rgba (Wuyi, Wuyi, 1));-webkit-backg Round-clip:text;-webkit-text-fill-color:transparent;
Although the CSS property used in this method is relatively more, but the structure is simple, easy to control, color selection and control is more accurate, understanding is also easier to understand. I personally recommend the use of method two.
Third, conclusion
Since the Text-fill-color and Mask-image properties appear to be WebKit core browser support, two demo pages can only be seen in Chrome or Safari. Firefox browser under the solid color, ie, not to mention.
However, the text gradient itself is a decorative function, so in the progressive enhancement of the principle, we in the actual project can actually be used boldly. Without affecting the original function on the basis of a few lines of CSS code, so that the share of the more and more high-quality Chrome browser has a better visual experience, why not?