center
已废弃
该特性已经从 Web 标准中删除,虽然一些浏览器目前仍然支持它,但也许会在未来的某个时间停止支持,请尽量不要使用该特性。
这个标签已经在 HTML 4(以及 XHTML 1)中废除了,以支持CSStext-align
属性,它可以用于 <div>
元素,或者独立的<p>
。对于居中的块,使用其它 CSS 属性,例如 margin-left
和margin-right
,并将其设置为 auto
(或者将 margin
设为0 auto
).
DOM 接口
这个元素实现了HTMLElement
接口。
实现注解: 直到 Gecko 1.9.2(包含), Firefox 为这个元素实现了 HTMLSpanElement
接口。
示例1
<center>This text will be centered.
<p>So will this paragraph.</p></center>
示例 2 (CSS 替代)
<div style="text-align:center">This text will be centered.
<p>So will this paragraph.</p></div>
示例 3 (CSS 替代)
<p style="text-align:center">This line will be centered.<br>
And so will this line.</p>
注
向<div>
或者 {HTMLElement("p")}} 元素应用 {Cssxref("text-align")}}:center
会使这些元素的内容居中,当它们的外形尺寸没有改变的时候。
浏览器兼容性
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | (Yes)1 | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | (Yes) | (Yes)1 | (Yes) | (Yes) | (Yes) |
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com