一行大小不一样的文字上下居中对齐
作者:互联网
一行大小不一样的文字上下居中对齐
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.div1, .div2 {
background-color: #cccccc;
}
.div1+.div2 {
margin-top: 40px;
}
.text1 {
font-size: 26px;
background-color: #c9e2b3;
}
.text2 {
font-size: 36px;
background-color: #a6e1ec;
}
.text3 {
font-size: 22px;
background-color: #ff7800;
}
.middle {
vertical-align: middle;
}
</style>
</head>
<body>
<!-- 默认是不对齐的 -->
<div class="div1">
<span class="text1">第一段文本</span>
<span class="text2">下一段内容</span>
<span class="text3">第三段内容</span>
</div>
<!-- 垂直方向居中对齐 -->
<div class="div2">
<span class="text1 middle">第一段文本</span>
<span class="text2 middle">下一段内容</span>
<span class="text3 middle">第三段内容</span>
</div>
</body>
</html>
- 每一段不同字体大小的文字用span标签包裹
- 给每一个span标签添加
vertical-align: middle;
参考:https://blog.csdn.net/mouday/article/details/124165756
标签:居中,color,align,一行,middle,background,对齐,font,size 来源: https://www.cnblogs.com/jia-zq/p/16659561.html