Jump to content

Can is use Image Sprites to define DIV backgrounds?


Dzomlija

Recommended Posts

The CSS Image Sprites reference has definitely helped me to simplify some of the UI aspects of a new personal website I'm designing, as I'm able to combine several images into one for various stages of display such as Normal, Hover and Mouse Down.

However, when it comes to the layout of some other UI elements, such as a modal "Dialog Box" that is opened when a button or link is clicked, I still have to use individual images to define the static or repeating images for the DIV backgrounds.

I have attached two files that demonstrate what I'm trying to accomplish. The first file ("dzomlija_dlg_sprites_demo.png") shows the various sprites I use to compile the results ("dzomlija_dlg_demo.png").

So my question is this: How do I compile all the relevant sprites into one singular image for use within the CSS definitions for my "Dialog Box".

Finding out the answer will solve a similar issue I have with the CSS definitions for MouseOver tooltips that I'm implementing...

dzomlija_dlg_sprites_demo.png

dzomlija_dlg_demo.png

Link to comment
Share on other sites

Sprites have limitations. For one, the container must be the same size in pixels as the sprite you're representing, otherwise other sprites on the same image are visible. Another limitation is that sprites cannot be repeating since background-repeat repeats the whole image file and not just a part of it.

In short, you can't style a flexible box using sprites.

On the other hand, you can use the border-image property in CSS to split an image into parts and use them to style a box.

  • Like 1
Link to comment
Share on other sites

Thank you, Ingolme.

The answer you provided is precisely what I've been looking for, and will most definitely be of use to me.👍

Now, if I can do the same but have the "Top Row" of the border (Top Left corner, Top Middle and Top Right corner) be of a different height without stretching (as shown in my original post image, the "DLG HEADER BAR"), then it'll really make my day.👌

Have a great day.

P.S. Your reply has also lead me to finding and downloading  Firefox Developer Edition , which I'm exploring now.

Border Image Demo.zip

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...