I don't understand this:
I have tried to center the text-align of a HTML <span>
tag but it did nothing...
With the <div>
tag, everything worked. Same sittuation with setting margin: 0px auto;
in css.
Why does the span tag not support the text-align;
function?
This question is related to
css
html
text-alignment
Span is considered an in-line element. As such is basically constrains itself to the content within it. It more or less is transparent.
Think of it having the behavior of the 'b' tag.
It can be performed like <span style='font-weight: bold;'>bold text</span>
div is a block element.
Spans are inline, divs are block elements. i.e. spans are only as wide as their respective content. You can align the span inside the surrounding container (if it's a block container), but you can't align the content.
Span is primarily used for formatting purposes. If you want to arrange or position the contents, use div, p or some other block element.
A span tag is only as wide as its contents, so there is no 'center' of a span tag. There is no extra space on either side of the content.
A div tag, however, is as wide as its containing element, so the content of that div can be centered using any extra space that the content doesn't take up.
So if your div is 100px width and your content only takes 50px, the browser will divide the remaining 50px by 2 and pad 25px on each side of your content to center it.
Like other have said, span is an in-line element.
See here: http://www.w3.org/TR/CSS2/visuren.html
Additionally, you can make a span behave like a div by applying a
style="display: block; margin: 0px auto; text-align: center;"
It might be, because your span element sets is side as width as its content. if you have a div with 500px width and text-align center, and you enter a span tag it should be aligned in the center. So your problem might be a CSS one. Install Firebug at Firefox and check the style attributes your span or div object has.
Source: Stackoverflow.com