关于html:textalign真的只是让文本居中吗

3次阅读

共计 545 个字符,预计需要花费 2 分钟才能阅读完成。

很多教程上说 text-align 属性只是让文本程度居中。但 text-align 的性能远不止如此。

对于具备文本类属性的元素,text-align属性也能够使其程度居中显示。

具备文本类属性的元素有:行内元素、行内块元素。也就是说 text-align 属性也能够使这些元素程度居中。

试验:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div style = "width: 600px; height: 300px; background: red; text-align: center;">
        <span>span 标签 </span>
        <a href="#">a 标签 </a>
        <img src="images/spanner1.jpg" alt=""style ="width: 50px;height: 50px">
    </div>
</body>
</html>

显示成果:

span, a, img 标签都是行内元素,在 div 中应用 text-align: center 程度居中

正文完
 0