CSS3 text gradients

Source: Internet
Author: User
Tags implement key

Before, we have published a CSS text gradient, but in fact it is not a purely CSS-based gradient, it needs a translucent gradient png picture. Today we'll introduce two ways to implement text using CSS3. Well, only WebKit browser support, please temporarily ignore other browsers.

1.-webkit-mask

In the future of CSS: some of the experimental CSS properties, we mentioned this attribute, compared to Firefox can only use SVG to do mask,webkit is a lot more flexible, picture and CSS3 gradient can be. It was initially noted that the effect was in the pjblog of Shun's son:

. textgradient1{
-webkit-mask:-webkit-gradient (linear,0% 0%,0% 100%,from (Rgba
				)), to ( RGBA (36,142,36,0.2));
}

Insufficient: This method is implemented with the transparency of the mask, and the color of the mask is not used in the gradient, from the example you can see that the settings of the gradient is ignored, the only useful alpha value. The gradient here depends on the color of the font-that is, only monochrome gradients are supported.

2.-webkit-background-clip:text

Strictly speaking, this method requires several attribute combinations, including color/-webkit-text-fill-color and background gradients:

. Textgradient2{background:-webkit-gradient (linear,
				0%
				0,
				0%
				100%, from (#DEBB47), to (#248F24));
Color:
				transparent;
/*-webkit-text-fill-color:transparent;*/
-webkit-background-clip:
				text;

Points:

    • The purpose of Color/-webkit-text-fill-color is to make text transparent because other browsers do not support the following attribute values, so the latter is recommended here, and the Color property makes the text transparent in other browsers.
    • The text value of the-webkit-background-clip property is unique to WebKit, and Gecko, opera, and IE9 support this property, but they do not support the text value, which is the key.
    • You should now be able to see this method by hollowing out the text to reveal the background color. So the background color is key here, and the background color gradient can use any color, so this method supports true color gradients.

Here is a simple online demo that previews the effect:

Of course, with the-webkit-text-stroke attribute, you can create a cooler CSS gradient effect.

Of course, if you have other browsers to implement a pure CSS gradient method, welcome to share:)



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.