It’s amazing how can’t I just pull out such a simple task.
We wish to have a menu (ul list) displayed inline, where, on top we have an image and, at the bottom, we have an anchor.
Something like the above:
<iimg> <iimg> <iimg>
<anchor> <anchor> <anchor>
The solution must be valid for IE 7 too.
I’ve tried text-align centered the image. No luck;
I’ve tried display:block; on the li, on -img on both…
I’ve also defined widths here and there (but the images could have variable widths (not sure));
I’ve tried margin: 0 auto; but it centers on the page, but not on the LI. :///
ralph.m, thanks a lot for your reply.
If by doing that, we can have the image inside the anchor and still have to text of the anchor to be underline when the user mouse over, then yes it would be feasible.
I’ve pissed off because this seems to be an easy task and I can’t pulled out! Arrgh!!!
Not sure what you mean by “padding: 10px will not be dropped when the user zooms in”
Because there’s no fixed widths it will work fine with different sized images.
now you just format your a as display:block, set it to the correct width&height and use your image as background on a.searchbtn. this way your visitors can click on the image and text, and you can sprite your background images together, saving you a few requests.
#1) Do it ONLY if your image is NOT content! It really would be a mess if you had to use different images or update the page… ugh.
If it is content the best solution is:
.searbutton a {display:block; text-align:center; padding-top: (height of image + let's say 10px); background:url(yourimage.jpg) no-repeat center 5px;}
This (or hapmsta )wont save any http request. It is a BAD idea to declare height AND with on text links, and for a spite technique to work you have to fave fixed dimensions. If you are dead set in using sprites… you could use the :before pseudo element but remember you will have to have some fixes for ltIE7
ul.searchbtn a{ display:block; }
ul.searchbtn li{ text-align:center;}
ul.searchbtn li:before{ display:block;content:""; background:url(yourimage.jpg) no-repeat center top; height:(height of your image); }