<center>: The Centered Text element
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
<center>
HTML 元素是一个 块级元素,它在其包含元素内水平居中显示其块级或内联内容。该容器通常是(但不必须是)<body>
。
¥The <center>
HTML element is a block-level element that displays its block-level or inline contents centered horizontally within its containing element. The container is usually, but isn't required to be, <body>
.
该标签在 HTML 4(和 XHTML 1)中已被弃用,取而代之的是 CSS text-align
属性,该属性可以应用于 <div>
元素或单个 <p>
。对于居中块,请使用其他 CSS 属性,例如 margin-left
和 margin-right
,并将它们设置为 auto
(或将 margin
设置为 0 auto
)。
¥This tag has been deprecated in HTML 4 (and XHTML 1) in favor of the CSS text-align
property, which can be applied to the <div>
element or to an individual <p>
. For centering blocks, use other CSS properties like margin-left
and margin-right
and set them to auto
(or set margin
to 0 auto
).
DOM 接口
实现例 1
结果
示例 2(CSS 替代方案)
结果
示例 3(CSS 替代方案)
结果
¥Result
注意:将
text-align
:center
应用于<div>
或<p>
元素会使这些元素的内容居中,同时保持其整体尺寸不变。¥Note: Applying
text-align
:center
to a<div>
or<p>
element centers the contents of those elements while leaving their overall dimensions unchanged.
规范
Specification |
---|
HTML Standard # center |
浏览器兼容性
BCD tables only load in the browser
也可以看看
¥See also