tags:

views:

303

answers:

4

Is there a way to create a color gradient in CSS without using an image file?

I am trying to give a DIV a background with a color gradient so that it looks glossy.

A: 

No this is not possible you just can set plain color in CSS. The only way to do is to create an image an set it as background.

#yourdiv {
  background: transparent url(yourimg.png) 0 0 scroll no-repeat;
}

EDIT: like said in the other answers it is possible in some browsers. But when speaking of possible I like to reefer to most the browsers.

Tim
Any good sites for getting good gradient images?
Brian
Creating gradients is very easy in Photoshop, GIMP or even online with Aviary: http://aviary.com/
pygorex1
+6  A: 

Safari (Webkit) supports it: http://webkit.org/blog/175/introducing-css-gradients/

Firefox 3.6+ supports it: https://developer.mozilla.org/en/CSS/-moz-linear-gradient

W3 spec defines support for it: http://dev.w3.org/csswg/css3-images/#gradients-

And you can use Modernizr to detect support and fall back on an image: http://www.modernizr.com/docs/#cssgradients

Renesis
Hm, and WebKit went ahead and invented their own syntax different from the W3 one. Genius. But still, keep in mind that the alleged "definition" is no more than a draft, so the W3C hasn't defined anything, they're still pondering how it might look like.
Joey
+1  A: 

Webkit browsers support pure-CSS gradients like this (see this example in Safari or Chrome) - but practically speaking for a cross-browser implementation you'll need to use images.

pygorex1
While still using images, a flexible solution: http://www.alistapart.com/articles/supereasyblendys/
donut