views:

214

answers:

3
<th>
  My Heading
  <a href="#" class="sort-asc" title="sort">Sort Asc</a>
</th>

I want to apply CSS to .sort-asc to replace the text "Sort Asc" with a custom 16x16 sort glyph image (/images/asc.png), placing the image directly to the right of the text. Is it possible?

NOTE: I can't change the markup. I can only apply styles; the following is my feeble attempt:

a.sort-asc {
    float: left;
    width: 16px;
    height: 16px;
    padding: 0;
    margin: 5px;
    display: block;
    text-indent: -2000px;
    overflow: hidden;
    background: url("/images/asc.png") no-repeat; 
}

Currently, the image shows up all the way to the left of the table header cell. I need it to the right of the text "My Heading".

A: 

Remove float and display:block for the text to appear next to the "My Heading" text.

Vincent Ramdhanie
Just did and now the image shows up behind "Sort Asc". I don't want "Sort Asc" to show up at all.
Travis Heseman
Try setting the color of the text to the same color as background - This is a bit ugly but... color:#FFFFFF; background-color:#FFFFFF;
Vincent Ramdhanie
+1  A: 

If you remove the display block, you won't be able to set your width, height or use text-indent to hide the copy within the A. Try changing display:block to display:inline (since you're floating) instead - it may give you what you need.

na_user
Changed "display: block;" to "display: inline;" - no change.
Travis Heseman
`Display` has no impact on floated elements, afaik.
Kobi
Well, to be fair, it does - it fixes double float bug margins on floated elements in IE6.
na_user
Fair enough. Welcome to Stack Overflow.
Kobi
+2  A: 
a.sort-asc {
    width: 16px;
    height: 16px;
    padding: 0;
    display:inline-block;
    text-indent: 200px;
    overflow: hidden;
    background: url("/favicon.ico") no-repeat; 
}

Removed float - you don't need it, it's on the right position. Text indent does nothing with inline, try inline-block: http://jsbin.com/abeme

Another hack is to add color: transparent, and a small size, but that too hacky.

Kobi