HTML教程-HTML<center>标签(HTML5 不支持)
HTML <center> 标签是一个块级元素,可以在其中包含块级元素和内联内容。在 <center> 元素之间编写的内容将显示在页面的中间。
HTML4 中已经弃用了 <center> 标签,在 HTML5 中被废弃了。
注意:<center> 标签现在已经被弃用,所以你可以使用 CSS 属性 text-align: center; 来实现相同的效果。
语法
<center>Add Content Here....</center>以下是 <center> 标签的一些规范:
| 属性 | 值 |
|---|---|
| 显示 | 内联 |
| 开始标签/结束标签 | 都有开始和结束标签 |
| 用法 | 文本 |
示例
使用 <center> 标签
<!DOCTYPE html>
<html>
<head>
<title>Center tag</title>
</head>
<body>
<h2>Example of center tag</h2>
<center>This content is displayed in the middle of the page, but try to use CSS property to align the content as this tag is deprecated now.</center>
</body>
</html>使用 CSS
<!DOCTYPE html>
<html>
<head>
<title>Center tag</title>
<style>
h2 {
text-align: center;
}
</style>
</head>
<body>
<h2>Example of center tag</h2>
<p>This content is aligned centered using CSS property.</p>
</body>
</html>输出
属性
HTML <center> 标签在 HTML 中不包含任何特定的属性,但支持全局属性(只要 <center> 标签尚未完全删除)。
支持的浏览器
| 元素 | Chrome | IE | Firefox | Opera | Safari |
|---|---|---|---|---|---|
<center> | 是 | 是 | 是 | 是 | 是 |
Chrome
IE
Firefox
Opera
Safari