且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

中心标签工作正常,但对齐属性不行!可能是什么问题?

更新时间:2023-02-18 17:43:13

不要使用这个.align 属性已弃用.

Don't use this. The align attribute is deprecated.

CSS 是首选方法,但是:

CSS is the preferred method but:

  • 应避免使用内联样式(使用 style 属性),而应使用真正的样式表.
  • CSS 中没有 align 属性

如果要将应用它的元素的内联内容居中或将左右边距设置为 auto 以居中,请使用 text-align 属性块元素.有关更多详细信息和图表,请参阅使用 CSS 居中.

Use the text-align property if you want to centre the inline content of the element to which you apply it or set the left and right margins to auto to centre block elements. For more details, and diagrams, see Centring using CSS.

此外,这仅发生在非 IE 浏览器中.IE 显示页面居中对齐,即使没有任何标签.

Also, this happens only in non-IE browsers. IE shows the page center aligned, even without any tags.

如果您没有触发标准模式的 Doctype,那么浏览器将模拟错误较早的浏览器(怪癖模式).这是您应该避免的事情,因为它会使事情变得不那么一致.

If you don't have a Doctype that triggers Standards mode, then browsers will emulate bugs in earlier browsers (Quirks mode). This is something you should avoid as it makes things much less consistent.

这些错误之一是,如果祖先设置了 text-align: center(并且不支持自动边距),则 Internet Explorer 会将块元素居中.

One of these bugs is that Internet Explorer will centre block elements if an ancestor has text-align: center set (and won't support auto margins).