Activate your free membership today | Log-in

Thursday, December 7th, 2006

Blendy Backgrounds Explained

Category: CSS, Tutorial

Matthew O'neill wrote a tutorial on Super-Easy Blendy Backgrounds:

Recently, while trying to implement a few different navigation ideas that a designer had thrown my way, I became frustrated with my weak image editing skills. The design was gradient-heavy, so a traditional approach to navigation markup and styling would require a dozen or so background-image slices to meet the varying colors and height requirements.

After spending a mortifying amount of time creating the images—I’m a programmer by trade, so anything more complicated than MS Paint gives me the willies—I had to take a step back and figure out a better way. What if, after finishing, I needed to tweak the height? Or, God forbid, the color palette? My head was going to explode if I had to open an image editor again, so the Super Easy Blendy Backgrounds technique was born.

The article follows the typical pattern of "hmm, well in IE 7 we found that you needed to do this" and walks you through all of the fixes (we won't say hacks).

They end up with:

CSS:
  1.  
  2. <style type="text/css">.grad img {
  3.   height: 100%;
  4.   left: 0px;
  5.   position: absolute;
  6.   top: 0px;
  7.   width: 100%;
  8.   z-index: 0;
  9. }
  10. .box {
  11.   border: solid orange 2px;
  12.   float: left;
  13.   margin: 1px;
  14.   position: relative;
  15.   width: 165px;
  16.   padding: 5px;
  17. }
  18. .box * {
  19.   margin: 0px;
  20.   position: relative;
  21.   z-index: 1;
  22. }
  23. * html .grad {
  24.   filter: progid:DXImageTransform.Microsoft.AlphaImage »
  25. Loader (src='grad_white.png', sizingMethod='scale');
  26. }
  27. * html .grad img {
  28.   display: none;
  29. }
  30. * html .box {
  31.     position:static;
  32. }
  33. .blue {
  34.   background-color: #2382a1;
  35. }
  36. .green {
  37.   background-color: #4be22d;
  38. }
  39. .pink {
  40.   background-color: #ff009d;
  41. }
  42. </style>
  43.  
  44. <!--[if IE 7]>
  45. <style type="text/css">
  46. .box {
  47.   border: solid red 2px;
  48.   height:2.5em;
  49. }
  50. </style>
  51. <![endif]-->
  52.  

Posted by Dion Almaer at 8:44 am

+++--
3.3 rating from 44 votes

26 Comments »

Comments feed TrackBack URI

Old news.

Comment by Mike — December 7, 2006

Very nice! I will try it out!

Comment by Oliver Tse — December 7, 2006

Old news, but still very cool!

(there, i fixed it for you.)

Comment by mdm-adph — December 7, 2006

Ugh. I really wanted to like this. But…
This requires adding an <img> element inside the <div>.
What happens when you’re tired of the blendy look? You have to change both the CSS and HTML, most likely removing the unsemantic <img>. Everywhere.
I’d prefer to see something like this confined to the CSS.
So, how many blendy colors do you need for a site? Hopefully no more than 5 or so. But even if it’s 10, prepare each in your favorite graphics tool, throw them into the CSS, and be done with it.
Now, lets clean up the semantics. Class names like “box grad pink” are presentation-specific. What if the client wants to change pink to orange? Again, changes in the HTML. I like a class to reflect the meaning of an element, rather than its appearance — like “action cancel”.
Finally, for button-like elements, the entire rectangular area should probably be active, rather than just the text. One way to do this is to style a link as a block.
So we end up with something like:
<a class="action" href=...>Buy Now</a>
and…
a.action {
display: block;
width: 10em;
float: left;
background:skyblue url(skyblue-blendy.gif) repeat-x;
}

Comment by Eric — December 7, 2006

For IE6-, use gradient filter will be easier

.foo{
_zoom:1;
_filter:progid:dximagetransform.microsoft.gradient(enabled=’true’, startcolorstr=#ffffff, endcolorstr=#4be22d)
}

a simple gradient

Comment by Hedger Wang — December 7, 2006

Dear Ajaxian,
before posting any articles, please check with Mike to see if he’s already heard of it.
Thanks!

Comment by Paradise Pete — December 7, 2006

Interesting Finds: December 7, 2006

Trackback by Jason Haley — December 7, 2006

All this code to make this ?
I make a same thing in five minuts making a texture in photoshop and it repeat-x….done.

Comment by Igor Escobar — December 8, 2006

you bunch of stupid people!!!! try to use that blendy with a gif in another background than white and you’ll see the results. this great example is used to combine the alpha opacity power of the png graphic (natively supported by firefox) with internet explorer, in a way that you can rezise the document and it’ll fit well. Of course it ani’t the best to do it, but it the most practical and efficient way to achieve that results.

Comment by truly webmaster — December 9, 2006

Hmm, looks like a lot of the commenters haven’t actually read the article. You can create fixed size gradients in “Your favourite pixel editor”, but you can’t make them stretch to fill a non-pre-defined space. The img and background colour route certainly works and is nicely controlled by the css for the container (div,etc).

(Like Igor said :) )

The author has tried to make this cross platform - so using a specific MS filter is Ok, if you don’t care about actually being cross-platform (and having extra code to handle the start/end colours - the authors route simply sets the background colour of the container!)

In my opinion, it’s a good article and nicely covers the cross-platform and current limitiations of HTML, etc.

Good work.

Comment by Dave Probert — December 9, 2006

see
Cross browser gradient without image.

Comment by gondalmk — January 11, 2007

Take a look at my example of making blendy tabs at: http://www.boriskuzmic.com/index.php?p=projects_css_js

Comment by Boris Kuzmic — February 19, 2007

Ihre Website ist wirklich sehr informativ-ich werde sicherlich noch öfters vorbeikommen und mir den ein oder anderen Tipp hier herauslesen.
thx

Comment by clever vv — May 27, 2007

I think these blog is really useful for new comers and Excellent resource list.
It´s a very interesting Blog and simple answer of many questions.
Keep up the good work!
Thanks it helps me a lot…

Comment by Onlineshop — May 28, 2007

great sit with good information
many greetings from germany Tee

Comment by Tee — June 11, 2007

Remember one thing about design is that it really isn’t so much about what you PUT IN but what you LEAVE OUT that makes for a good, simple, but creative design. Few designers realise this. With the increasing popularity of CSS and web 2.0 environments, this is becoming more the norm (simple) but I’m worried that creativity is now being lost in the process. Everyone looks the same, functions the same. While I’d rather have standardization on a more clean look (in other words, in the 90’s the standard was “messy, links everywhere, and horrible banners”) we mustn’t throw creativity out all together!

Comment by Make Money — August 9, 2007

a very iteresting articel, thank you very much

Comment by Hotels in Bremen — October 10, 2007

Also thanks. I enjoyed reading the article

Comment by Fernstudium — October 21, 2007

a very iteresting articel, thank you very much I love Ajax
varmısın yokmusun
Kız Oyunları

Comment by cicicocuk — February 3, 2008

Its good to know Ajax, but you should get to know java first.

Comment by przeprowadzki — March 12, 2008

I’m not a programmer yet, But I want to be a programmer and try my best for that.
I must to study java and then to learn Ajax?

My search:canada sildenafil

by hgi5lu8 on Tues. Apr. 22, 2008

Comment by hgi5lu8 — April 22, 2008

Looks like great

Oyun Oyna

Comment by 3123630866 — May 2, 2008

nice trick, but sometime IE acts strange when using filter to load png image. I haven’t figure yet why it happens yet

Comment by backgroundsMaster — June 4, 2008

Thanks so much.
Bebek Oyunlar?

Comment by cicicocuk — July 31, 2008

very thanks for you…
Oyun

Comment by Oyun — August 16, 2008

great article.

Comment by erichansa — October 13, 2008

Leave a comment

You must be logged in to post a comment.