CSS3 Implementing a gradient text effect

Source: Internet
Author: User
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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.