很多教程上说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
程度居中