Difference between and
with text-align:center;?

前端 未结 6 1163
粉色の甜心
粉色の甜心 2020-12-01 02:24

I don\'t understand this:

I have tried to center the text-align of a HTML tag but it did nothing... With the

tag,
6条回答
  •  日久生厌
    2020-12-01 02:52

    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.

提交回复
热议问题