meow
meow

Reputation: 28184

What is the easiest cross-browser compatible way of creating gradients with CSS?

I noticed this being used by a service, and the effect looks super great

-moz-linear-gradient(center top , #E3EBF3, #D5E1ED) repeat scroll 0 0 transparent

Upvotes: 0

Views: 164

Answers (2)

AndrewPK
AndrewPK

Reputation: 6150

http://www.colorzilla.com/gradient-editor/

use modernizr and some if IE blocks at the top to add classes to your html tag so that you can provide valid HTML and CSS, and hacks&properties to those necessary.

for instance, in a gradient I've used in the past:

body {
background: #2688cf;
}
.cssgradients body{
background: -moz-linear-gradient(top, #2688cf 0%, #2989d8 12%, #207cca 14%, #62a2d6 18%, #b9d5ea 28%, #ffffff 40%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#2688cf), color-stop(12%,#2989d8), color-stop(14%,#207cca), color-stop(18%,#62a2d6), color-stop(28%,#b9d5ea), color-stop(40%,#ffffff));
background: -webkit-linear-gradient(top, #2688cf 0%,#2989d8 12%,#207cca 14%,#62a2d6 18%,#b9d5ea 28%,#ffffff 40%);
background: -o-linear-gradient(top, #2688cf 0%,#2989d8 12%,#207cca 14%,#62a2d6 18%,#b9d5ea 28%,#ffffff 40%);
background: linear-gradient(top, #2688cf 0%,#2989d8 12%,#207cca 14%,#62a2d6 18%,#b9d5ea 28%,#ffffff 40%);
}

.ie6 body, .ie7 body, .ie8 body, .ie9 body {
background: -ms-linear-gradient(top, #2688cf 0%,#2989d8 12%,#207cca 14%,#62a2d6 18%,#b9d5ea 28%,#ffffff 40%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#2688cf', endColorstr='#ffffff',GradientType=0 );
background: linear-gradient(top, #2688cf 0%,#2989d8 12%,#207cca 14%,#62a2d6 18%,#b9d5ea 28%,#ffffff 40%);
}

Upvotes: 0

alex
alex

Reputation: 490657

Use the CSS property like you have in your question. Add the -moz, -webkit prefixes, then use it prefixless.

IE's filter property can do gradients. It is propriety, but it works :)

Upvotes: 3

Related Questions