首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

center

已废弃

该特性已经从 Web 标准中删除,虽然一些浏览器目前仍然支持它,但也许会在未来的某个时间停止支持,请尽量不要使用该特性。

HTML Center 元素 (<center>) 是个块级元素,可以包含段落,以及其它块级和内联元素。这个元素的整个内容在它的上级元素中水平居中(通常是<body>)。

这个标签已经在 HTML 4(以及 XHTML 1)中废除了,以支持CSStext-align属性,它可以用于 <div>元素,或者独立的<p>。对于居中的块,使用其它 CSS 属性,例如 margin-leftmargin-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)

扫码关注腾讯云开发者

领取腾讯云代金券