CSS文字水平居中且宽度自适应
<div class="a">
<div class="b">测试<div>
</div>
<style>
.a{
width: 200px;
height: 200px;
position: relative;
}
.b{
position: absolute;
top: 20px;
left: 0;
right: 0;
margin: auto;
width: fit-content; //根据文字长度自适应
background: blue;
}
</style>