Advertisement
Advertisement


Does height and width not apply to span?


Question

Total noob question, but here.

CSS

.product__specfield_8_arrow {

    /*background-image:url(../../upload/orng_bg_arrow.png);
    background-repeat:no-repeat;*/
    background-color:#fc0;
    width:50px !important;
    height:33px !important;
    border: 1px solid #dddddd;
    border-left:none;
    border-radius:5px;
    -moz-border-radius:5px;
    -webkit-border-radius:5px;
    border-bottom-left-radius:0px;
    border-top-left-radius:0px;
    -moz-border-radius-bottomleft:0px;
    -moz-border-radius-topleft:0px;
    -webkit-border-bottom-left-radius:0px;
    -webkit-border-top-left-radius:0px;
    margin:0;
    padding:2px;
    cursor:pointer;
}​​​

HTML

<span class="product__specfield_8_arrow">&nbsp;</span>​

Fiddle

Basically I'm trying to emulate a button, make a span (or something) look like a button next to an input field that actually doesn't need to be one because of an auto fill generator that generates errors onEnter. Thought this'd be a quick fix for now but obviously not.

Thanks.

2014/08/26
1
259
8/26/2014 2:56:58 PM

Accepted Answer

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.

span.product__specfield_8_arrow
{
    display: inline-block; /* or block */
}
2020/04/02
435
4/2/2020 12:28:13 PM

Try using a div instead of the span or using the CSS display: block; or display: inline-block;span is by default an inline element which cannot take width and height properties.

2010/03/22

Inspired from @Hamed, I added the following and it worked for me:

display: inline-block; overflow: hidden; 
2016/06/17

Span takes width and height only when we make it block element.

span {display:block;}
2013/05/20

As per comment from @Paul, If display: block is specified, span stops to be an inline element and an element after it appears on next line.

I came here to find solution to my span height problem and I got a solution of my own

Adding overflow:hidden; and keeing it inline will solve the problem just tested in IE8 Quirks mode

2014/03/27

spans are by default displayed inline, which means they don't have a height and width.

Try adding a display: block to your span.

2010/03/22

Source: https://stackoverflow.com/questions/2491068
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]