我想在圆圈内显示通知计数,但我不希望它具有固定宽度,以便当圆圈内有更大的数字/文本时圆圈可以扩展。
.circle {
height: 20px;
width: 20px;
line-height: 20px;
border-radius: 50%;
background-color: red;
color: white;
text-align: center;
}
<div class="circle">5</div>
<br>
<div class="circle">102</div>
原文由 xperator 发布,翻译遵循 CC BY-SA 4.0 许可协议
请参阅此仅 CSS 解决方案。为 1 位数字设置相同的值
min-width
和min-height
。使用伪元素进行垂直对齐并保持正方形。 withborder-radius
适用于圆容器。