<center>标签用于将其中的内容居中显示。在HTML5中已经不推荐使用该标签,而是通过CSS的text-align: center;来实现文本居中。
语法
<center>内容</center>
属性
<center>标签没有任何属性。
示例
// www.javascriptcn.com code example
<!DOCTYPE html>
<html>
<head>
<title>Center Example</title>
</head>
<body>
<center>
<h1>This is centered text</h1>
<p>This is a paragraph of centered text.</p>
</center>
</body>
</html>在上面的示例中,<h1>和<p>标签中的文本都会被居中显示。
注意事项
- 不推荐使用
<center>标签,应该使用CSS来控制文本的对齐方式。 - 为了确保网页在不同设备上的展示效果一致,应该避免使用
<center>标签。
以上就是关于<center>标签的介绍和示例代码。