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

body{
  background-color:#ccc;
  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

body{
  background-color:#ccc;
  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.

Comentarios

  1. t.co [#]

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

  2. http://t.co/54yyFOsfye [#]

    Informative article, exactly what I needed.

  3. http://j.mp/3mG8gY3 [#]

    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 http://ivermectin1.com/ 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 https://tadalafili.com/

  7. vampire community gay dating [#]

    safe gay dating sites https://datinggayservices.com/

  8. gay dating sites germany [#]

    gay naked dating https://gay-singles-dating.com/

  9. gay male speed dating nyc [#]

    dating sites gay chubby https://gaydatingcanada.com/

  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! https://hhydroxychloroquine.com/

  11. quest bars in [#]

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

    Keep up the great writing. quest bars http://bitly.com/3C2tkMR quest bars

  12. ivermectin1.com [#]

    ivermectina coronavirus Gradientes con CSS 3 | CSSLab | Laboratorio de ideas web http://ivermectin1.com/ ivermectin tablets

  13. ivermectin1.com [#]

    stromektolvätska Gradientes con CSS 3 | CSSLab | Laboratorio de ideas web http://ivermectin1.com/ ivermectin dosage

  14. app.gumroad.com [#]

    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 https://app.gumroad.com/asmr2021/p/best-asmr-online asmr

  15. gay christian dating service [#]

    hot gay dating sites https://gaydatinglosangeles.com/

  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 http://bitly.com/3jZgEA2 quest bars

  17. http://j.mp/3yWVlmR [#]

    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 https://0401mm.tumblr.com/ scoliosis surgery

  18. http://coub.com/ [#]

    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 https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

  19. bitly.com [#]

    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
    http://1704milesapart.tumblr.com/ cheap flights

  20. bit.ly [#]

    Keep on writing, great job! ps4 games https://bit.ly/3z5HwTp 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
    site.

  22. http://bit.ly/ [#]

    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 http://1704milesapart.tumblr.com/ cheap flights

  23. http://www.iherb.com/search?kw=questbars [#]

    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 https://www.iherb.com/search?kw=quest%20bars quest bars

  24. http://bitly.com/3nkdKIi [#]

    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 https://bitly.com/3nkdKIi ps4

  25. xyzal samples for providers [#]

    zyrtec vs allegra – https://allergyd.com

  26. cetirizine sale [#]

    zyrtec side effects – http://allergyd.com

  27. side effects of allegra 24 [#]

    cetirizine sam’s – https://allergyd.com

  28. dhcmqqafybd [#]

    btaHU5 xmlbaratdevf, [url=http://zbiwktoknrcw.com/]zbiwktoknrcw[/url], [link=http://knegkoafdlgt.com/]knegkoafdlgt[/link], http://haumxoimrzkl.com/

  29. provigil100mg [#]

    https://modafinilprovigilok.com/ modafinil provigil

  30. bactrim dosage [#]

    Sulfamethoxazole trimethoprim trimoxazole tablets

  31. ivermectina comprar [#]

    cena stromektolu https://stromectolforte.com/ ivermectin ivermectin tablets for humans

  32. kapalina stromectol [#]

    stromectol pills http://stromectolforte.com/ 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. http://harmonyhomesltd.com/Ivermectinum-during-pregnancy.html

  34. ivermektin 3 mg tablettdos [#]

    ivermectin where to find http://stromectolforte.com/ stromectol tablets for humans cost of ivermectin cream

CSSLab