中心标签工作正常,但对齐属性不行!可能是什么问题? [英] Center tag works fine, but align attribute doesn't! What may be the issue?

查看:49
本文介绍了中心标签工作正常,但对齐属性不行!可能是什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个完整的页面与框架的中心对齐,如果我使用 center 标签,它工作正常.但是,如果我使用

I am trying to align a complete page, to the center of a frame, and if I use center tag, it works fine. But, if I use

<body align=center>

<body style="align:center">

它不对齐页面,但默认保持左对齐.现在,老实说,我是 HTML 的新手,所以我不太清楚,这可能是什么原因造成的.此外,这仅发生在非 IE 浏览器中.IE 显示页面居中对齐,即使没有任何标签.

it doesn't align the page, but keep it left-aligned as default. Now, I am a newbie at HTML to be honest, so I don't have much idea, what may be causing this. Also, this happens only in non-IE browsers. IE shows the page center aligned, even without any tags.

虽然它没有多大意义,因为我总是可以使用 center 标签,但是很高兴知道为什么 align 属性不起作用.请让我知道,如果有人知道问题是什么.

Although, it is not of much significance, as I can always use center tag, but its nice to know why align attribute doesn't work. Kindly let me know, if anyone got any idea, as to what is the problem.

事实证明,这是因为怪癖模式.谢谢大卫和镇!:D

Turns out, it is because of quirks mode. Thanks David and Town! :D

推荐答案

不要使用这个.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).

这篇关于中心标签工作正常,但对齐属性不行!可能是什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆