<分区>
<分区>
我是 CSS 的新手,看过一些关于如何在 div 中居中文本的指南,但现在它还没有完全居中,但几乎居中...
图片:https://cdn.discordapp.com/attachments/554447633197039627/595281754135199754/unknown.png
CSS:
.info { /* Background (div)*/
background-color: red;
height: 10em;
width: 50em;
position: absolute;
left: 50%;
top: 50%;
margin:-5em 0 0 -25em;
text-align: center;
}
.info-text { /* Text (span) */
font-size: 6em;
display: inline-block;
vertical-align: middle;
}
最佳答案
您可以使用 flex
通过 align-items:center
和 justify-content:space-between
向父级显示
还有其他方法,但我更喜欢这个!
*{
margin:0;
padding:0;
}
.center-text{
width:300px;
height:150px;
background:red;
display:flex;
align-items:center;
justify-content:space-around;
}
p{
font-size:30px;
}
<div class="center-text">
<p>Hello World</p>
</div>
关于html - 文本在 Div 中没有完全居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56853023/