views:

492

answers:

4

I want take a section of a picture, for example the middle of a picure, and repeat only that section in the background of a div. Is this even remotely possible? I suppose I could do this in javascript, but that would be messy.

In theory the answer to my question should be able to take a single pixel from a picture and repeat it in a line, or as a solid background.

Does anyone have any idea how I could do this in CSS?

+1  A: 

You might be able to achieve this effect using the CSS3 border-image property.

Unfortunately, I am not aware of a way to do this sort of thing in CSS2. Also, I don't think that you can do this via CSS sprites, because sprites don't stretch parts of your image—they just allow you to show certain parts of the image.

Steve

Steve Harrison
You can use javascript to simulate border-image on non CSS3 compliant browser. See: http://www.lrbabe.com/sdoms/borderImage/index.html
legenden
This is excellent and is exactly what i'm looking for. Thanks Steve and Legenden!
B T
A: 

If you want a cross-browser solution, then currently you're out of luck, especially if you want a CSS-solution.

The only way to do it with JavaScript would be through the canvas element, but that's not supported by IE.

Rene Saarsoo
A: 

CSS cannot do this. You can however do it server-side or by using SVG graphics or Flash. Note that doing it with a plugin would not technically be a 'background-image", you'd need to position your content over the top of it.

SpliFF
+1  A: 
Jonathan Sampson