Gradientes con CSS 3

22/Nov/2010 234

Muchas de las propiedades CSS3 han estado presentes en browsers Webkit como Safari y Chrome desde sus inicios; a medida que avancen han mejorado el soporte y no es diferente con el uso gradientes sólo con CSS. Desde la versión 3.6 se pueden utilizar con Firefox, y últimamente han tomado mucha fuerza en aplicativos web modernos.

¿Porqué utilizar gradientes en CSS en vez de imágenes?

  1. Es más flexible y mantenible
  2. Menos dependendias de programas y editores gráficos
  3. Menos consultas al servidor
  4. Es escalable

En este artículo abordaremos las maneras de escribir gradientes (lineales y radiales) para los principales navegadores modernos.

Según los estándares W3C, crear gradientes se compone de:

linear-gradient( [<punto> || <angulo>,]? <stop>, <stop> [, <stop>]* )
radial-gradient( [<posicion> || <angulo>,]? [<forma> || <tamaño>,]? <stop>, <stop>[, <stop>]* )

Para browsers Mozilla, se mantiene pero se agrega el prefijo -moz:

-moz-linear-gradient( [<punto> || <angulo>,]? <stop>, <stop> [, <stop>]* )
-moz-radial-gradient( [<posicion> || <angulo>,]? [<forma> || <tamaño>,]? <stop>, <stop>[, <stop>]* )

Y para Webkit, es bastante diferente:

-webkit-gradient(<tipo>, <punto> [, <radio>]?, <punto> [, <radio>]? [, <stop>]*)

Una lástima que tengamos que reescribir para cada uno diferentes propiedades para lograr el mismo efecto. Mejor veamos los ejemplos:

Gradiente Lineal

  background-image: -moz-linear-gradient(top, #333, #ccc);
  background-image: -webkit-gradient(linear, left top,left bottom, from(#333), to(#ccc));
  background-image: linear-gradient(top, #333, #ccc);

Ver Ejemplo

Gradiente Radial

  background-image: -moz-radial-gradient(center 45deg,circle cover, #ccc, #333);
  background-image: -webkit-gradient(radial, 50% 50%, 0, 50% 50%,800, from(#ccc), to(#333));
  background-image: radial-gradient(center 45deg,circle cover, #ccc, #333);

Ver Ejemplo

¿Y con Internet Explorer?

Ni lo pienses, siquiera en IE9 están soportados. Podrías lograrlo en esta última versión através de SVG, el cual es basado en vectores. SVG es un lenguaje de marcado basado en XML que descibre vectores, y el motor de HTML5 permite que SVG sea incrustado directamente en HTML. Definiendo el alto del documento SVG al 100%, tendremos una imagen que se escala cualquiera sea el alto del elemento, tal como lo haría una caja con gradientes en CSS3.

¿Muy complicado? También lo creo. Mejor prueba algún script como Modernizr ó CSS3 Pie, los que hacen que IE soporte CSS3 como deberían haberlo hecho con los estándares hace mucho tiempo ya.


  1. [#]

    Greetings! Very helpful advice within this article! It is the little changes that produce the
    greatest changes. Thanks a lot for sharing!

  2. [#]

    Informative article, exactly what I needed.

  3. [#]

    Thanks for finally talking about > Gradientes
    con CSS 3 | CSSLab | Laboratorio de ideas web < Liked it!

  4. hydroxychloroquineMt [#]

    buy plaquenil hydroxychloroquine generic can hydroxychloroquine cause blindness

  5. ivermectin [#]

    stromectol order online Gradientes con CSS 3 | CSSLab | Laboratorio de ideas web stromectol cost

  6. cialis vs sildenafil side effects [#]

    If you are going for best contents like myself, only
    pay a visit this web site everyday since it offers quality contents, thanks

  7. vampire community gay dating [#]

    safe gay dating sites

  8. gay dating sites germany [#]

    gay naked dating

  9. gay male speed dating nyc [#]

    dating sites gay chubby

  10. youtube hydroxychloroquine treatment update [#]

    My brother suggested I might like this blog.
    He was totally right. This post truly made my day.
    You cann’t imagine just how much time I had spent for this information! Thanks!

  11. quest bars in [#]

    Excellent article! We will be linking to this great content on our website.

    Keep up the great writing. quest bars quest bars

  12. [#]

    ivermectina coronavirus Gradientes con CSS 3 | CSSLab | Laboratorio de ideas web ivermectin tablets

  13. [#]

    stromektolvätska Gradientes con CSS 3 | CSSLab | Laboratorio de ideas web ivermectin dosage

  14. [#]

    all the time i used to read smaller articles that also clear their motive, and that is also happening
    with this article which I am reading at this time. asmr asmr

  15. gay christian dating service [#]

    hot gay dating sites

  16. or quest bars [#]

    I don’t even know how I ended up here, but I thought this post was great.
    I don’t know who you are but certainly you’re going to a
    famous blogger if you are not already 😉 Cheers!
    quest bars quest bars

  17. [#]

    Link exchange is nothing else but it is just placing the other person’s blog link on your page at appropriate place and
    other person will also do similar for you. scoliosis surgery scoliosis surgery

  18. [#]

    Hey I know this is off topic but I was wondering if you knew
    of any widgets I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some
    time and was hoping maybe you would have some experience with something like this.

    Please let me know if you run into anything. I truly enjoy
    reading your blog and I look forward to your new updates.
    scoliosis surgery scoliosis surgery

  19. [#]

    Fantastic goods from you, man. I have understand your stuff previous to and you
    are just too magnificent. I actually like what you’ve acquired here,
    really like what you are stating and the way in which you say it.

    You make it entertaining and you still take care of to keep it
    sensible. I can’t wait to read much more from you.
    This is actually a wonderful site. cheap flights cheap flights

  20. [#]

    Keep on writing, great job! ps4 games ps4 games

  21. vjudi [#]

    I have read several good stuff here. Definitely worth bookmarking for revisiting.
    I surprise how much attempt you set to create the sort of wonderful informative

  22. [#]

    Having read this I thought it was very informative.
    I appreciate you taking the time and effort to put this content together.
    I once again find myself spending a significant amount of time both reading and leaving comments.
    But so what, it was still worth it! cheap flights cheap flights

  23. [#]

    What’s up to all, as I am genuinely keen of reading this web site’s post to be updated on a regular basis.
    It contains fastidious information. quest bars quest bars

  24. [#]

    You need to take part in a contest for one of the best blogs
    on the web. I’m going to recommend this website! ps4 games ps4

  25. xyzal samples for providers [#]

    zyrtec vs allegra –

  26. cetirizine sale [#]

    zyrtec side effects –

  27. side effects of allegra 24 [#]

    cetirizine sam’s –

  28. dhcmqqafybd [#]

    btaHU5 xmlbaratdevf, [url=]zbiwktoknrcw[/url], [link=]knegkoafdlgt[/link],

  29. provigil100mg [#] modafinil provigil

  30. bactrim dosage [#]

    Sulfamethoxazole trimethoprim trimoxazole tablets

  31. ivermectina comprar [#]

    cena stromektolu ivermectin ivermectin tablets for humans

  32. kapalina stromectol [#]

    stromectol pills ivermectin ivermectin for humans where to buy locally

  33. ivermectin plus [#]

    I for all time emailed this webpage post page to all my friends, for
    the reason that if like to read it next my links will too.

  34. ivermektin 3 mg tablettdos [#]

    ivermectin where to find stromectol tablets for humans cost of ivermectin cream