Wednesday, October 12, 2011

Span element width

If you've ever tried setting a width to a <span> element, you'll find that somehow it just doesn't work. I just found out that the reason for this is that elements that have display:inline property set, will ignore width (because inline elements will automatically assume the smallest possible width.

So you can fix this by doing something like

span {
  display: inline-block;
  width: 50px;
}

.. and according to the HTML spec, <span> is an inline element.