<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-leftmargin-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 接口

¥DOM interface

该元素实现 HTMLElement 接口。

¥This element implements the HTMLElement interface.

实现例 1

¥Example 1

html
<center>
  This text will be centered.
  <p>So will this paragraph.</p>
</center>

结果

¥Result

示例 2(CSS 替代方案)

¥Example 2 (CSS alternative)

html
<div style="text-align:center">
  This text will be centered.
  <p>So will this paragraph.</p>
</div>

结果

¥Result

示例 3(CSS 替代方案)

¥Example 3 (CSS alternative)

html
<p style="text-align:center">
  This line will be centered.<br />
  And so will this line.
</p>

结果

¥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

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also