Spans
are inline elements and have the width of their respective contents. If you want to set a specific width, use block elements like div
or p
and arrange them horizontally with float:left;
<div style="border: 1px solid black; width:300px;">
<div style="float:left; background: red; width:100px;">one</div>
<div style="float:left; background: yellow; width:100px;">two</div>
<div style="float:left; background: red; width:100px;">three</div>
</div>
Generally speaking, span
is used for formatting purposes, like setting font style, etc. Block elements like div
can be used for layout and positioning.
You can tweak spans
to do the same, but it's not recommended. Divs
are there for this exact purpose.