gpt4 book ai didi

html - 无法使文本居中居中

转载 作者:太空宇宙 更新时间:2023-11-03 21:17:45 25 4
gpt4 key购买 nike

.css {
background: highlight none repeat scroll 0 0;
border-radius: 50%;
color: rgb(255, 255, 255);
height: 10px;
padding: 3px;
text-align: center;
width: 10px;
font-size:10px
}

height & widthfont-size不能少于或多于 10px .

<div class="css">4</div>

您对此有解决方案吗?

最佳答案

最简单的方法是将 line-height 设置为元素的 height

.css {
background: highlight;
border-radius: 50%;
color: rgb(255, 255, 255);
height: 10px;
padding: 3px;
text-align: center;
width: 10px;
font-size: 10px;
line-height: 10px;
}
<div class="css">4</div>

另一种方法是使用 Flexbox 并设置 align-items: centerjustify-content: center

.css {
background: highlight;
border-radius: 50%;
color: rgb(255, 255, 255);
height: 10px;
padding: 3px;
width: 10px;
font-size: 10px;
display: flex;
align-items: center;
justify-content: center;
}
<div class="css">4</div>

关于html - 无法使文本居中居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40576678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com