<center>: 居中文本元素
已弃用:此特性不再推荐。虽然某些浏览器可能仍然支持它,但它可能已经从相关的网络标准中删除,可能正在删除过程中,或者可能仅为兼容性目的而保留。请避免使用它,如果可能,请更新现有代码;请参阅本页底部的兼容性表格以指导您的决策。请注意,此特性可能随时停止工作。
<center>
HTML 元素是一个 块级元素,它会将其块级或内联内容在容器内水平居中。容器通常是 <body>
元素,但并非必须。
此标签在 HTML 4 (和 XHTML 1) 中已弃用,推荐使用 CSS 的 text-align
属性,该属性可应用于 <div>
元素或单独的 <p>
元素。要居中块级元素,请使用其他 CSS 属性,如 margin-left
和 margin-right
,并将它们设置为 auto
(或将 margin
设置为 0 auto
)。
DOM 接口
此元素实现了 HTMLElement
接口。
示例 1
html
<center>
This text will be centered.
<p>So will this paragraph.</p>
</center>
结果
示例 2 (CSS 替代方案)
html
<div class="center">
This text will be centered.
<p>So will this paragraph.</p>
</div>
css
.center {
text-align: center;
}
结果
示例 3 (CSS 替代方案)
html
<p class="center">
This line will be centered.<br />
And so will this line.
</p>
css
.center {
text-align: center;
}
结果
注意: 将 text-align: center
应用于 <div>
或 <p>
元素会居中这些元素的内容,而不会改变它们的整体尺寸。
规范
规范 |
---|
HTML # center |
浏览器兼容性
加载中…