tags:

views:

76

answers:

1

Hi, I'm trying to design a link with an image background, question is if the image is too large, how do i fit it to the width and height of the anchor using css?

<a href="#"></a>
<style>
 a
 {  
    display: block;
    padding: 5px 12px;
    border: 1px solid black;
    width: 10px;
    height: 10px;
    background-image: url('/Scripts/images/downarrow_blue.png');
    }
</style>

tia, Lina

+1  A: 

Background images in CSS 2.1 cannot be resized, although CSS 3 supports the background-size property it's not widely implemented.

background-size: 10px 10px;

The obvious alternative is to just use an <img> tag:

<a href="#"><img src="mybg.png" alt="" style="width:10px; height:10px" /></a>    

But you probably have a reason for not doing it that way anyway, right?

Other alternatives might be

  • Resize the <a> element to the size of the image instead.
  • Resize the image locally and upload it under a different filename.
  • Use a server-side preprocessor such as PHP or ASP to deliver the image in the size you want.
Andy E
yes i actually have a reason for using it as a background, as i have to change the picture on hover, thank you :)
Lina