Super-Easy Blendy Backgrounds

by Matthew O'Neill

63 Reader Comments

Back to the Article
  1. Thanks for your article. It’s very useful.
    However,how can I put images in the boxes ?
    I’ve tried to set the z-index to “2” and higher but it’s no help.
    Please help me,thanks a lot!!

    Copy & paste the code below to embed this comment.
  2. “When viewing the final bendy background example in firefox the alt tag text is showing up in the browser without the need to hover the mouse over the box.“

    This isn’t my experience, with Firefox 2 on XP.

    NOTE TO EDITORS: Please fix the missing end tag for the code on the previous page of comments! It is turning everything after into Courier, including the side bar!

    Copy & paste the code below to embed this comment.
  3. Please don’t add alt attribute to decorative images! It should be an empty string:
    <img alt=”“>

    “guidelines on alt by J.Korpela”:http://www.cs.tut.fi/~jkorpela/html/alt.html

    Copy & paste the code below to embed this comment.
  4. What happened to separating content from presentation? It’s a great technique, but using <img >s as backgrounds?

    Hmmm…

    Copy & paste the code below to embed this comment.
  5. Cool technique. Although the scaling of images sends a cold chill down my spine, it stinks of the 1px transparent gif trick for object spacing ( which was only ever used by the lazy and incompotent ). Resizing images forces the browser to waste cpu cycles doing what it’s not really very good at. Given all the other stuff we are forcing browsers to cope with I can’t see how that’s a good idea. And you just know that somebody is going to put this in a div which they will then resize dynamically. Oh the horror!!!

    Copy & paste the code below to embed this comment.
  6. It’s very interesting and I guess there’s no limits to what’s can be done with css!

    Copy & paste the code below to embed this comment.
  7. It looks pretty, but from a semantic perspective, adding an image for purely presentational purposes is iffy.  Screen reader users will experience the annoyance of having their reader say “image” each time one of these boxes is “read out” aloud.

    Copy & paste the code below to embed this comment.
  8. AS of IE 5, you can also produce gradients exclusively with Style Filters.  The gradient is exclusively HTML and CSS.  it does not require an image

    Copy & paste the code below to embed this comment.
  9. #48 (and others with screenreaders)

    Havent you heard about setting the media in the css include?


    <style type=‘text/css’ media=‘aural’>
    /* Aural = screenreader */
    .img { display:none; }
    </style>

    <style type=‘text/css’ media=‘print’>
    /* print = if printing */
    .img { display:none; }
    </style>

    Copy & paste the code below to embed this comment.
  10. “AS of IE 5, you can also produce gradients exclusively with Style Filters.“

    IE5.5 to be precise.

    “The gradient is exclusively HTML and CSS. it does not require an image.“

    And only works in one single browser, Internet Explorer, available for one single platform, Windows. The web has moved on. People use Macs. People use Linux. People use mobile phones. Browsers today include a wide range of available programs. Anything IE-only is to be completely avoided (unless your page degrades nicely without the IE-only special effects).

    It’s a shame, because filters were one of the coolest things to hit the web. You can use them to rotate images for instance, so only one gif is needed for a four-corner frame. Or have a black and white photo turn to colour on hover just by using a filter.

    Copy & paste the code below to embed this comment.
  11. Is it really worth it? Is it really worth all the haggle and all that messy markup/CSS-code to save in a few bytes of image-files? I think not. I’d rather preffer ten image-files weighing a few kilobytes rather than having all that extra code to mess up my stylesheet and markup, especially on a large webpage with a complex layout.

    You could do it server side (or probably with JS), though, but that again would leave far more work than just making it as images in the first place.

    Nice method for experimenting, understanding and learning, but I dont think i will be using it a lot.

    Copy & paste the code below to embed this comment.
  12. Learning CSS with this type of good article and demo is fun… great job!!
    Thanks Matthew O’Neill.

    Copy & paste the code below to embed this comment.
  13. Why does this break in IE 6 when I remove the float:left from the .box? (It will still work in Firefox.)

    Copy & paste the code below to embed this comment.
  14. nice article, and good concept to apply.
    The part to make PNG work in IE using AlphaImageloader seems to be misplaced though.
    Why would one require a filter to do other filters’ job, that too using external images?

    please look up http://msdn.microsoft.com/workshop/author/filter/reference/filters/gradient.asp
    My idea will be to get gradients in IE without using any imges, keep the PNG gradeient of FF and other browsers though.

    Copy & paste the code below to embed this comment.
  15. Opera doesn’t like padding on the containing div—it seems to still apply the padding to the absolutely positioned image, but on the right side of the div. Removing the padding or placing it on another element (such as a nested span) apparently fixes this.

    An example: http://prisoner34.com/blendy/

    Copy & paste the code below to embed this comment.
  16. Sorry, but this time it wasn’t :( I frequently find ALA articles interesting, even when I can’t find them an inmediate use. But not this time.

    When I became aware of what a PNG can do I tried this trick, but found most of the problems already mentioned in the article and the comments. But the worst, for me, is that it isn’t enough to mix a color with white or black to make it look good!

    Considering that any 256×256 2-color PNG linear gradient is about 860 bytes long and that I can create it with 7 mouse clicks and a filename, I doubt I’ll bother with the second part of the article.

    Copy & paste the code below to embed this comment.
  17. … some Browsers don’t support the transparency of PNGs?

    Copy & paste the code below to embed this comment.
  18. I can see maybe, maybe using this for mock-ups, but with today’s graphic tools, creating high-quality gradients is easy.

    I really suggest avoiding this technique and making backgrounds with what they are intended: the background property. At least the background property is cross-platform and has very few issues with various layout techniques (floats, absolute positions, etc) where this method can easily break down.

    Copy & paste the code below to embed this comment.
  19. I applaud the creativity, but it has a major down side.  The img elements in the markup are not really content, but are shown as such by web clients that aren’t css aware or that have css turned off.

    We needed scalable background images for a project several months ago and went with this technique.  Our web site navigation now looks horrible in non-css browsers, like cell phones, lynx, or even ie/win in accessibility mode.  it also probably makes users of screen readers unhappy.

    Its a neat hack, but not a good production solution.

    Copy & paste the code below to embed this comment.
  20. It uses a CSS hack.
    I never have used hacks in any of my css. Never will.

    I will see if I can come up with the same technique and no hacks.

    Copy & paste the code below to embed this comment.
  21. I mean, it works – yeah. And it’s a pretty good idea. Very original thought process. It just seems like so much extra work to achieve something you can do with a couple of seconds in photoshop with the gradient tool.

    Great idea, really. Just seems a bit excessive to make a gradient.

    Copy & paste the code below to embed this comment.
  22. I recently rediscovered the Power of PNG 24bit transparencies after running some wonderful tests in FireFox and went ga-ga over it. Of course I repeated the tests in IE 6 and wanted to cry… support for this is non existent without going above and beyond compliant mark up for CSS, I wonder how long IE7 will take to hit the masses hard with Windows Vista out. Then we can go Nuts!

    Copy & paste the code below to embed this comment.
  23. I must say that this technique is really great. It also inspired me to create blendy tabs, to use for site navigation. Take a look at:
    http://www.boriskuzmic.com/index.php?p=projects_css_js

    Copy & paste the code below to embed this comment.