16

A straight forward question.. is it possible to set the width in percentage for a span tag in CSS? for example:

<span style="width: 50%">...</span> 

etc..

In my project I'm currently using divs but ofcourse after each div tag a line break gets inserted (which I don't want). So the most obvious solution to that is then to use span tags instead of div. But then I'm not able to define the width for the span tags.. Atleast not in a percentage kind of way.

Thanks in advance for any help!

  • possible duplicate of [CSS width of a tag](http://stackoverflow.com/questions/621401/css-width-of-a-span-tag) – Manse Apr 10 '12 at 08:44

3 Answers3

34

Define the element as an inline block and you can control the width and height like a block element while keeping it inline with surrounding content.

#element {
  display: inline-block;
  width: 50%;
}
thomthom
  • 2,854
  • 1
  • 23
  • 53
3

inline elements cannot have dimensions. do them to do so, and still remain inline, add:

display: inline-block
Joseph
  • 117,725
  • 30
  • 181
  • 234
0

Add display: flex; on parent div style.

<div style="display: flex;">
    <span style="width:50%">...</span>
    <span style="width:50%">...</span>
</div>
Babita Tokas
  • 131
  • 1
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 17 '22 at 20:23