Quick Tip: Nonintrusive CSS Text Gradients
Tutorial Details
- Topic: CSS Text Gradients
- Difficulty: Moderate
- Tutorial Format: Video
Though not completely cross browser compatible, there are ways to nonintrusively create pure CSS text-gradients with a bit of trickery. The key is to use a mix of attribute selectors, webkit-specific properties, and custom HTML attributes.
Final Simple HTML
Hello World
By using custom attributes, we can then hook into these values from within our stylesheet by using the attr() function.
Final CSS
/* Select only h1s that contain a 'data-text' attribute */
h1[data-text] {
position: relative;
color: red;
}
h1[data-text]::after {
content: attr(data-text);
z-index: 2;
color: green;
position: absolute;
left: 0;
-webkit-mask-image: -webkit-gradient(
linear,
left top, left bottom,
from(rgba(0,0,0,1)),
color-stop(40%, rgba(0,0,0,0))
);
Note: Paul referenced an even more succinct method in the comments. Be sure to check that out as well!
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
- http://rommelcastro.me Rommel
- Randito
- Christophor S. Wilson
- Michael P.
- Webkitz
- http://andredublin.com Andre
- http://barrywalsh-portfolio.com Barry
- http://www.smartenough.org DNABeast
- Mudassir
- NoName
- http://www.maisui99.com 小豪
- http://tommasoraspo.com Raspo
- http://www.code.my devlim
- Felipe
- http://www.customicondesign.com custom icon design
- http://www.aaron.im Aaron
- http://joshriser.com Josh
- http://www.maughan.net.au/ Ryan Maughan
- http://www.maughan.net.au/ Ryan Maughan
- http://www.paulgrock.com Paul Grock
- http://www.smartenough.org DNABeast
- http://css-tricks.com Chris Coyier
- http://www.paulgrock.com Paul Grock
- Sleeman
- http://www.thedevelopertuts.com Bratu Sebastian
- RZV
- dan
- RZV
- M Burke
- http://devignsight.com Tim
- http://creativecart.blogspot.com/ Dinesh Verma
- RZV
- http://filcp.com Filipe Carrano Pacheco
- w1sh
- Alex Devine
- http://www.css3files.com Chris
- arafat
- http://www.my-html-codes.com HTML Codes Dude
- http://mitchmckenna.com Mitchell McKenna
- http://www.duzmath-tamas.hu/honlapkeszites Honlapkészítés
- http://deveedutta.net63.net/ Deveedutta
