homepage Welcome to WebmasterWorld Guest from 54.211.219.178
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / CSS
Forum Library, Charter, Moderators: not2easy

CSS Forum

    
sprites and repeating background images
slicing sprites
mihomes




msg:4322733
 5:39 am on Jun 7, 2011 (gmt 0)

Been fooling around with sprites lately and having trouble using them as a repeating background...

For instance, say I have this :


#footer{
width:100%;
background-image:url('/images/footerback.png');background-repeat:repeat-x;
height:66px;
line-height:66px;
font-size:11px;
color:#888888;
text-decoration:none;
}


Lets say footerback.png is 15x66 pixels and is my repeating background for the above div. As shown it works fine.

Now, what if footerback.png is part of a collection of images... say... sprite.png at x=0 y=50...

Is it possible to repeat that specific portion of the image? I can get the footer to start off at the right position, but it repeats the entire sprite.png and not the specific portion of it I wish.

Is it even possible to use css sprites as repeating backgrounds or must they be contained within a defined size...ie non-repeating?

 

alt131




msg:4324029
 2:21 pm on Jun 9, 2011 (gmt 0)

Hi mihomes,

Unfortunately you are right - background-images repeat in full, not parts or "slices". I've looked at this several times since you posted the question, but nothing has occurred to me yet. That includes thinking about some of the options available in the css3 "Backgrounds and Borders" module. There has been some discussion about adding a "background-image-slice" property that would do what you want, but no developments on that yet.

So not an ideal response - but a fascinating challenge. Can anyone else think of another approach?

mihomes




msg:4324078
 3:20 pm on Jun 9, 2011 (gmt 0)

It is possible... but all horiz repeats need to be together and all vertical need to be together... you then make sure the width is the same on all, or the height is the same...

For instance... all horiz repeats are aligned vertically with the same width.

mihomes




msg:4324079
 3:21 pm on Jun 9, 2011 (gmt 0)

Not very practical though it what I am trying to say...

alt131




msg:4324157
 5:12 pm on Jun 9, 2011 (gmt 0)

Well, that would depend on what you were trying to do :)

I may have been incorrect, because I read "collection of images" as a collection similar to below - of the sort used by amazon.com which is a common example.
|||||||||||||||||||||||||||||
||####|||****|||^^^^^||
||####|||****|||^^^^^||
|||||||||||****|||^^^^^||
||%%||~~~~|||||^^^^^||
||%%||~~~~|||||||||||||||

- and the goal was to repeat just one of those images horizontally and vertically across the background of any element.

The technique you described is different because the image "collection" is specifically prepared to suit the element's width/height and the element is sized according to the width/height of the image that will be visible.

As you say, that has limitations, but I got some interesting results using the before and after pseudo elements - although that defeats the purpose if sprites are being used to reduce server hits. There is also the technique of making the dimensions of the image collection large enough to avoid other images being visible, and/or "layering" multiple backgrounds to create the repeating effect - with the obvious disadvantage of increased image size, therefore increased bandwidth consumption, and/or increase hits as well.

Was this a general question, or did you have a specific code situation in mind? I ask because although the above aren't suitable as general solutions, it might be possible to think of a technique to achieve the desired outcome if you provide a bit more detail.

mihomes




msg:4324207
 6:54 pm on Jun 9, 2011 (gmt 0)

You were correct in the manner I was using this - one single 'collection of images' which would be used on most pages.

So, basically the only thing I could do is have a seperate image file for certain background repeat images... I might play around with it later today and will post some results, however, combining two or three images that repeat into one would not be a very huge savings...

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / CSS
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved