简体   繁体   English

如何在文本上应用 CSS 渐变,从透明颜色到不透明颜色

[英]How to apply a CSS gradient over a text, from a transparent to an opaque colour

Cheers!干杯!

I am a newbie in CSS/HTML, but I want to apply a gradient over a text, like that on the image below.我是 CSS/HTML 的新手,但我想在文本上应用渐变,如下图所示。 How can I implement it with css?我怎样才能用css实现它?


在此处输入图片说明

The relevant CSS is on the pseudoelement :after of the <article> wrapper I used相关的 CSS 位于伪元素上:after我使用的<article>包装器之后

 article { position: relative; } article:after { position: absolute; bottom: 0; height: 100%; width: 100%; content: ""; background: linear-gradient(to top, rgba(255,255,255, 1) 20%, rgba(255,255,255, 0) 80% ); pointer-events: none; /* so the text is still selectable */ }
 <article> <p> Had you stepped on board the Pequod at a certain juncture of this post-mortemizing of the whale; and had you strolled forward nigh the windlass, pretty sure am I that you would have scanned with no small curiosity a very strange, enigmatical object, which you would have seen there, lying along lengthwise in the lee scuppers. Had you stepped on board the Pequod at a certain juncture of this post-mortemizing of the whale; and had you strolled forward nigh the windlass, pretty sure am I that you would have scanned with no small curiosity a very strange, enigmatical object, which you would have seen there, lying along lengthwise in the lee scuppers. </p> </article>

CSS3 text gradients that is only supported by Webkit based browsers like Chrome and Safari. CSS3 文本渐变仅受基于 Webkit 的浏览器(如 Chrome 和 Safari)支持。 I have used 3 different methods.我使用了 3 种不同的方法。 check this fiddle first http://jsfiddle.net/sarfarazdesigner/pvU7r/ Try this首先检查这个小提琴http://jsfiddle.net/sarfarazdesigner/pvU7r/试试这个

.article{
  background: -webkit-linear-gradient(#eee, #333);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

this is working fine in chrome don't know how other browser react.这在 chrome 中运行良好,不知道其他浏览器如何反应。 Reference taken from http://css-tricks.com/snippets/css/gradient-text/参考来自http://css-tricks.com/snippets/css/gradient-text/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM