HTML的center标签 - HTML5 不支持


HTML中的center标签是用来将其包含的内容在页面中居中显示的标签。该标签已经过时,不建议再在现代化的网站中使用。HTML5中推荐使用CSS来实现页面布局和居中等样式。

使用center标签的示例代码如下:

<center>
  <h1>Welcome to my website</h1>
  <img src="image/logo.png" alt="Logo">
  <p>Here you can find the latest news and updates.</p>
</center>

上述代码中,center标签将所有内容都居中对齐。其中包含了一个标题,一个图像和一个段落文字。

center标签具有一些属性用来进一步控制对齐方式:

  • align:指定对齐方式,可选值为left、center和right。该属性已经废弃,不建议使用。
  • dir:指定文字方向,可选值为ltr(从左到右)和rtl(从右到左)。

以下是一个示例演示如何使用align属性实现左对齐、居中对齐和右对齐:

<center align="left">
  <h1>Welcome to my website</h1>
  <img src="image/logo.png" alt="Logo">
  <p>Here you can find the latest news and updates.</p>
</center>

<center align="center">
  <h1>Welcome to my website</h1>
  <img src="image/logo.png" alt="Logo">
  <p>Here you can find the latest news and updates.</p>
</center>

<center align="right">
  <h1>Welcome to my website</h1>
  <img src="image/logo.png" alt="Logo">
  <p>Here you can find the latest news and updates.</p>
</center>

除了使用属性控制对齐方式,center标签还可以嵌套使用以实现更复杂的布局。例如:

<center>
  <table>
    <tr>
      <td>Left Column</td>
      <td>Center Column</td>
      <td>Right Column</td>
    </tr>
  </table>
</center>

上述代码中,center标签包含了一个包含了三列文字的表格。由于表格默认是居中对齐的,因此不需要使用align属性来控制对齐方式。

总体来说,虽然center标签可以让内容更加美观,但由于其已经过时,不安全且不兼容现代化浏览器,建议使用CSS进行内容对齐和布局。