views:

37

answers:

4

So I need some custom colors on a layout, but I'm looking for a better way of doing it other than just slapping a giant picture with (background: url(something.jpg)) in the layout.

Mostly I'm thinking of getting a color palette (i.e. from Adobe Kuler, colourlovers, etc.), getting a 5x5 sample of each color and sticking them in an array for CSS sprites or just as separate files and accessing them through: .color-one {transparent url(./one.gif) repeat} and just reusing that whenever I'd like to use the color.

Are there any drawbacks to doing it this way? And if there are should I just stick with web-safe colors or is there a better way of doing this?

+1  A: 
.color-one{background-color: #f00}
.color-two{background-color: #0f0}
graphicdivine
Thanks for the quick repsonse. I'd vote you up if could :( .
ineedtosleep
+1  A: 

You have to set the colors as background-color anyway to serve readers which don't load images. So I see no use in those images.

And remember: the smaller an image is the more has the browser to compute to calculate all positions. Repeated background images should not be smaller than 20×20px.

toscho
"Repeated background images should not be smaller than 20×20px." - really? hmm.. can you show some documentation on this?
Derek Adair
The dimensions are taken just from my experience; I don’t have good data, sorry. The [GWT FAQ says](http://code.google.com/intl/de/webtoolkit/doc/latest/FAQ_UI.html#Why_do_I_see_poor_performance_when_using_a_one_pixel_tall_backgr)> Be advised, however, that there can be a performance penalty for covering a large area with a small image (in particular, we noticed the problem on Internet Explorer).
toscho
+4  A: 

You don't need graphics to represent background colors. You are going the long way around if you use images for that. Just use colors, as graphicsdivine suggests.

Only use background images if you need to do gradients and the like. That's really where they shine.

As to your second question, no, you don't need to stick with "web-safe" colors anymore. If someone in 2010 still only can display 256 colors, well, your site won't be their biggest problem.

Robusto
Ah thanks. It's been a while since I've dealt with colors this intimately and don't know why I thought only websafe colors would work on background-color: #. Thanks.
ineedtosleep
A: 

Why don't set background-color?

(And your suggestion wouldn't work with sprites, the renderer will also use the other parts of the image)

neo