gpt4 book ai didi

css - 在 CSS3 中居中内部圆形 Div

转载 作者:行者123 更新时间:2023-11-28 17:51:40 25 4
gpt4 key购买 nike

你能看看this CSS DEMO吗?让我知道如何将内部 div 居中放置在外部 div 中,并将内部 div 的文本居中放置?

.outer{
width: 100px;
height: 100px;
background: #fc2e5a;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
}
.inner {
width: 80px;
height: 80px;
background: #fff;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
}

<div class="outer">
<div class="inner">Test</div>
</div>

最佳答案

不使用 table-cellflex-boxposition 如果您知道 div 的确切大小,那么您可以这样做:

.outer{
width: 100px;
height: 100px;
padding: 10px;
border-radius: 50%;
background: #fc2e5a;
-moz-box-sizing: border-box;
box-sizing: border-box;
}

.inner {
width: 80px;
height: 80px;
line-height: 80px;
border-radius: 50%;
text-align: center;
background: #fff;
}

这是 demo

请注意,我删除了 border-radius 的浏览器特定前缀,并将其设置为 50% 以使其独立于整个尺寸。

关于css - 在 CSS3 中居中内部圆形 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22187849/

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