Align contents inside a div

后端 未结 8 2007
时光取名叫无心
时光取名叫无心 2020-12-22 15:50

I use css style text-align to align contents inside a container in HTML. This works fine while the content is text or the browser is IE. But otherwise it does not work.

8条回答
  •  时光取名叫无心
    2020-12-22 15:58

    text-align aligns text and other inline content. It doesn't align block element children.

    To do that, you want to give the element you want aligned a width, with ‘auto’ left and right margins. This is the standards-compliant way that works everywhere except IE5.x.

    Hello

    For this to work in IE6, you need to make sure Standards Mode is on by using a suitable DOCTYPE.

    If you really need to support IE5/Quirks Mode, which these days you shouldn't really, it is possible to combine the two different approaches to centering:

    Hello

    (Obviously, styles are best put inside a stylesheet, but the inline version is illustrative.)

提交回复
热议问题