Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

css

Cheers!

I am a newbie in CSS/HTML, but I want to apply a gradient over a text, like that on the image below. How can I implement it with css?


  enter image description here

like image 773
xamenrax Avatar asked Jan 24 '13 11:01

xamenrax


People also ask

How do you add a gradient color to text in CSS?

To add a gradient overlay to a text element, we need to set three different CSS properties to the text we want to style: background-image: <gradient> background-clip: text. text-fill-color: transparent.

How do you make a gradient opacity in CSS?

Linear Gradient - Transparency To add transparency, we use the rgba() function to define the color stops. The last parameter in the rgba() function can be a value from 0 to 1, and it defines the transparency of the color: 0 indicates full transparency, 1 indicates full color (no transparency).

How do I add a gradient to an image in CSS?

To create a linear gradient you must define at least two color stops. Color stops are the colors you want to render smooth transitions among. You can also set a starting point and a direction (or an angle) along with the gradient effect.


2 Answers

The relevant CSS is on the pseudoelement :after of the <article> wrapper I used

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> 
like image 166
Fabrizio Calderan Avatar answered Oct 09 '22 09:10

Fabrizio Calderan


CSS3 text gradients that is only supported by Webkit based browsers like Chrome and Safari. I have used 3 different methods. check this fiddle first http://jsfiddle.net/sarfarazdesigner/pvU7r/ Try this

.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. Reference taken from http://css-tricks.com/snippets/css/gradient-text/

like image 29
The Mechanic Avatar answered Oct 09 '22 11:10

The Mechanic