Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The background image in the span won't show without any text in the span tag

Tags:

html

css

The span below will not background image if I remove the inner text xxx

<span style='background-image:url("http://gifsoup.com/web/images/soc4.gif")'  style="height: 30px;">
 xxx
</span>

However it works without the xxx in the compatibility mode.

How do I make it work without any inner text?

like image 569
Foo Avatar asked Apr 17 '13 19:04

Foo


2 Answers

Because spans default to inline elements that don't have a width or height. Change the CSS to:

span {
    display:inline-block;
    width:30px;
    background-image:url("http://gifsoup.com/web/images/soc4.gif");
    height:30px;
}

jsFiddle example

By changing the display from inline to inline-block you can set the width and height of the span.

like image 134
j08691 Avatar answered Oct 05 '22 10:10

j08691


the span element is an inline element and as such has no width or height. you must specify in the elements css that it should be displayed as either block or inline-block and then specify the width and height for the image.

span{
    display: inline-block;
    background-image:url("http://gifsoup.com/web/images/soc4.gif");
    width:30px;
    height:30px;
    border-radius: 5px;
}

Example

like image 21
Chris Traveis Avatar answered Oct 05 '22 09:10

Chris Traveis