CSS Gradients in Action

Chris Williams has been having some fun with CSS gradients on a quest to create nice looking elements without images.

He uses CSS like this:


  1. .albumInfo {
  2. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#626262), to(#000000), color-stop(.5, #202020), color-stop(.5, #000000));
  3. height: 8em;
  4. padding: 1em;
  5. border-top: 1px solid #858585;
  6. border-bottom: 1px solid #505050;
  7. }
  8. .albumInfo h1 {
  9. font-weight: bold;
  10. text-shadow: 0px -1px 1px black;
  11. font-size: 1.2em;
  12. }
  13. ul.tracks {
  14. background: -webkit-gradient(radial, 50% -70, 0, 50% 0, 200, from(#595959), to(#0d0d0d)) #0d0d0d;
  15. width: 25.7em;
  16. }
  17. ul.tracks li.odd {
  18. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(255,255,255,.05)), to(rgba(255,255,255,.05)));
  19. }

This example demonstrates the power of WebKit’s implementation of gradients in css. This similar looking display to that of the iPhone album display uses a radial gradient (opposed to a linear) as the background for the track names. The overall effect is a dim light. The odd numbered tracks also use a gradient to take advantage of -webkit-gradient’s support of alpha values.

None of the gradients will work in other browsers. Check that your background and text are not the same color. The outermost div is set to black so it's viewable in other browsers.

Sheer Heart Attack is my favorite Queen album. I'm also quite fond of A Night At The Opera.


If you have better solution, just tell me !

0 comments: