Pure CSS3 text color gradient - Is it possible?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 03:03:12

问题


Is there a way to create a cross-browser, pure CSS3 text color gradient?

So, no png's. No 'webkit' only.

EDIT: To be more precise: It's CSS3 only, and it's for text, not box gradients.

EDIT: I found this solution, but it's only for webkit.


回答1:


There is no cross-browser way to do this outside webkit because only webkit currently has a background-clip: text, and this extension to background-clip is not on standards track (as far as I am aware). If you want to relax your CSS3 requirement, you can accomplish the same effect cross-browser with Canvas (or SVG), but then you're talking about HTML5-capable browsers only.




回答2:


There is no "pure" CSS way at the moment, but there is a way using CSS and some duplication of content. See my server side css gradient text solution here, which doesn't require JavaScript or plain background. You can also do this client side using JavaScript, see what Dragonlabs has done here.




回答3:


As I've already pointed out as a comment in zzzzBov's response, there is a way to achieve a text gradient in CSS3 only.

If you take the PNG solution a bit further, you can do the same trick with css3 gradients.

Of course this does only work for text that is on a uniform background color.




回答4:


Best solution at the moment is to use a solid color as non-webkit fallback and then use the following technique ( requires webkit ):

h1 {
  color: $333;
  font-size: 72px;
  background: -webkit-linear-gradient(#eee, #333);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
<h1>Example</h1>


来源:https://stackoverflow.com/questions/4740033/pure-css3-text-color-gradient-is-it-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!