There is a problem. The CSS code doesn’t show the complete height of the menu (notice the bottom). “tab-left.png” is 44px, altough the website shows just 30px. Any idea how can I solve this problem?
Yes just use the one image as long as your text is never going to be longer than that image (or that the zoomed text doesn’t overflow within reasonable limits).
You shouldn’t need to change much apart from the image url and some padding.
The remainder of the padding is on the parent list so that the left edge which is 6px wide is protected and not covered by the image on the anchor which is placed on top. If there were no padding on the list then the image on the anchor would rub out the left corner.
If you change the padding to px then you can work it out easier.
li {padding:0 0 0 6px}
li a{padding:0 24px 0 18px}
Thanks!
I would like to add an aditional image file (active.png) for active links. I think, this one is enough:
#navbar ul li.active {
background: url(img/active.png) no-repeat top left;
}
#navbar ul li.active a {
background: url(img/active.png) no-repeat top right;
}
(I assume mean for the current link on a page and not the pseudo class :active.)
Yes that should work fine but you could also incorporate that into the original sprite as well if you wanted.
Just create a double image with the highlighted image underneath the other one at a set number of pixels down. then you just change the background-position properties for the li.active.
Say the second image is stacked 100px from the top of the whole image:
#navbar ul li.active { background-position:0 -100px;}
#navbar ul li.active a { background-position:100% -100px;}
If so then when you lay the right side of the image on top of the image underneath then the image below shows through the transparent portions.
Usually you would use non transparent pngs for sprites like this assuming you are keeping then on the same white background.
If you want transparent pngs then you need to ensure that the transparent parts are moved away from the image underneath so that it doesn’t show through the transparent corners which as you found out can be done with negative margins in most cases.