views:

48

answers:

3
<style type='text/css'>
#span1{
background-image:url("http://www.reoiv.com/images/rss.jpg");
background-repeat:no-repeat;
cursor:pointer;
display:block;
float:left;
height:15px;
width:15px;
vertical-align:text-bottom;
}
</style>

<span id='span1'></span>觀看次數

What I would like to do is to achieve the vertical align: text-bottom effect but I am not doing it on a image element. I am doing it on an element with background-image set. If you paste the above codes here: http://htmledit.squarefree.com/

You will see that the text failed to vertically align to bottom.

I would like to know how it can be done without adding extra html element if possible.

Many thanks to you all.

+3  A: 

You closed the span tag before your text:

<span id='span1'></span>觀看次數

Use this:

<span id='span1'>觀看次數</span>

Hope that helps.

Kyle Sevenoaks
+1  A: 

You can't do that with floats. You could try using display: inline-block, but browser support is sketchy.

EDIT: http://www.quirksmode.org/css/display.html

RoToRa
It's not sketchy, it's good except for IE... naturally. IE only applies it to elements that are naturally inline - and span being one of them, it would work.
ANeves
@ANeves: You are right. I wrote the "sketchy" part before looking up the link. I somehow seemed to recall that FF3 had problems with it, but that doesn't seem to to be true.
RoToRa
Well, you are right as well, I was just being picky and grumpy - I agree that sketchy is a good word to describe it. But it's always the IE curse, always, always. What other browser do we expect to be outdated? What other browser do some people still expect version 6 even when version 9 is almost out there?!? That's trully ridiculous. =|
ANeves
+1  A: 

You can't get pixel perfect results. Here is a work around I've been using:

<span style="background: url(http://www.reoiv.com/images/rss.jpg) no-repeat left center; padding-left: 20px;">觀看次數</span>

This vertically center-aligns the icon nicely with the text. padding-left works nicely with inline elements.

Salman A