Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an image to an anchor tag using CSS?

Tags:

html

css

I'm making an anchor tag look like a button by using an image, but it doesn't show anything in the browser.

This is my code so far...

HTML

<span>
    <a id="knapNyhed" href="file:///E:/Projekt_skolespil/hjemmeside/index.html"></a>
</span>

CSS

.knapNyhed{
    background-image: pic/knap_nyhed_layout_00.png;
    width:226px;
    heigth: 50px;
    margin: 0 2px 0 2px;
}

Hope you can help with why I can't see my button

like image 381
Liv Darling Avatar asked Jun 18 '13 13:06

Liv Darling


1 Answers

You have to add display:block or display:inline-block as a tags are set to display:inline by default and inline elements can't have a width, height or margin.

To get the background image working you have to add url. Please note that this url is relative to your css file.

#knapNyhed {
  display:block;
  background-image: url(pic/knap_nyhed_layout_00.png);
  width:226px;
  heigth: 50px;
  margin: 0 2px 0 2px;
}
like image 59
jantimon Avatar answered Sep 17 '22 20:09

jantimon