Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set height property for SPAN

Tags:

html

css

height

I need to make following code stretchable with predefined height

<style> .title{    background: url(bg.gif) no-repeat bottom right;    height: 25px; } </style>  <span class="title">This is title</span> 

But since span is inline element, "height" property won't work.

I tried using div instead, but it will expand up to the width of upper element. And the width should be flexible.

Can anyone suggest any good solution for this?

Thanks in advance.

like image 476
Kelvin Avatar asked Feb 26 '10 18:02

Kelvin


People also ask

Can you set line height on span?

If you want to make the line-height bigger than the containing block, you have to change the containing block's size. If you want to make it smaller than the text and/or image, you need to use inline-bolck .

Do spans have height?

The main thing to remember about a span element is that it is an inline element, which means that you will not be able to set the width or height of it as is.

Can we add width and height to span?

Span is an inline element. It has no width or height. You could turn it into a block-level element, then it will accept your dimension directives.


2 Answers

Give it a display:inline-block in CSS - that should let it do what you want.
In terms of compatibility: IE6/7 will work with this, as quirks mode suggests:

IE 6/7 accepts the value only on elements with a natural display: inline.

like image 94
casraf Avatar answered Oct 23 '22 15:10

casraf


Use

.title{   display: inline-block;   height: 25px; } 

The only trick is browser support. Check if your list of supported browsers handles inline-block here.

like image 35
Jon Galloway Avatar answered Oct 23 '22 16:10

Jon Galloway