CSS3 Gradients

css3 gradients

Use CSS 3 to create some nice subtle gradients; or very compelling gradients!

CSS 3 Gradients are not the simplest things by any means; there are several values to account for when projecting your gradient and it only worsens when working with radial gradients.

background:-moz-linear-gradient(pos, #AAA B, #XXX Y);
pos = the position of the first colour, giving direction to the gradient
#AAA = primary colour
B = where the fade begins (%)
#XXX = secondary colour
Y = where the fade begins (%)

The -webkit-gradient() is built slightly differently but works in the same manner, creating a start position and then the colors from() and to();

CSS 3 Linear Gradient

The above layer uses the following CSS 3

  1. CSS3 Gradient (linear_1)
  2. .my_CSS3_class {
  3.   height: 100px;
  4.   background: -moz-linear-gradient(top, #35425d 0%, #fff 100%);
  5.   background: -webkit-gradient(linear, left top, left bottom, from(#35425d), to(#fff));
  6.   background: -o-gradient(#35425d , #fff);
  7. }

The above layer uses the following CSS 3

  1. CSS3 Gradient (linear_2)
  2. .my_CSS3_class {
  3.   height: 100px;
  4.   background: -moz-linear-gradient(left, #35425d 25%, #fff 100%);
  5.   background: -webkit-gradient(linear, left top, left bottom, from(#35425d), to(#fff));
  6.   background: -o-gradient(left, #35425d , #fff);
  7. }
 

CSS 3 Radial Gradient

When it comes to radial gradients, I find trial-by-error works(!). As with the linear gradients, we create a central start point, a primary color and a secondary color. To get your gradient to just how you want it though, that will take some playing, saving and f5′ing – again and again and again.

The above layer uses the following CSS 3

  1. CSS3 Gradient (radial)
  2. .my_CSS3_class {
  3.   height: 250px;
  4.   background: -moz-radial-gradient(50% 50%, farthest-side, #487a77, #fff);
  5.   background: -webkit-gradient(radial, 50% 50%, 0, 50% 50%, 350, from(#487a77), to(#fff));
  6. /* opera cannot create radial gradients yet */
  7. }
 

The Zen Elements CSS3 Series

Thank you for reading!
@zenelements // alex

Like this article?

Subscribe to our rss, follow our tweets or please help us spread the work & share this with your friends!

Thank you for all your support; have a cookie!

7 Comments on “CSS3 Gradients”

  1. Alex Devine 29.04.2010 at 11:54 am

    I really like the effects produced by CSS3, thanks for the tips :)

  2. Free gallery Belisma 10.05.2010 at 8:55 pm

    Super fantastic post, thank you!

  3. Adie 16.06.2010 at 6:22 pm

    Thankyou CSS3. Much nicer producing gradients like this rather than in photoshop

  4. Ingie 24.03.2011 at 3:00 pm

    This is freakin’ awesome!

  5. saran 27.04.2011 at 1:10 pm

    no idea for ie..!!! but really very nice

  6. nazirah 27.10.2011 at 1:50 pm

    OM……GOODWORK!

    this tutorial was so brilliant!i have try to my blog and it good on both mozilla & chrome..thanks! :) i really love this!

  7. saajan maharjan 21.12.2011 at 7:07 am

    awesomeness on css evolution.

 

Leave a Reply

(required; who are you?)

(required; we'll keep it safe!)

(optional; promote your site!)