the difference is not between
<div> specifically, but between
<span> defaults to being
<div> defaults to being
display:block;. But these can be overridden in CSS.
The difference in the way
text-align:center works between the two is down to the width.
block element defaults to being the width of its container. It can have its width set using CSS, but either way it is a fixed width.
inline element takes its width from the size of its content text.
text-align:center tells the text to position itself centrally in the element. But in an
inline element, this is clearly not going to have any effect because the element is the same width as the text; aligning it one way or the other is meaningless.
block element, because the element’s width is independent of the content, the content can be positioned within the element using the
Finally, a solution for you:
There is an additional value for the
display property which provides a half-way house between
inline. Conveniently enough, it’s called
inline-block. If you specify a
<span> to be
display:inline-block; in the CSS, it will continue to work as an inline element but will take on some of the properties of a block as well, such as the ability to specify a
width. Once you specify a width for it, you will be able to center the text within that width using