首先,使用margin: auto;不是黑客
为了让你的圆圈在圆圈内居中,你可以使用定位技术,比如position: absolute;. 在这里,我position: absolute;在内圈上使用,而不是分配值为topand的属性,而不是使用and并减去 and 的1/2 。left50%margin-topmargin-leftheightwidth
为什么要扣分32px?正如我已经说过的那样,我正好扣除了总数的一半width,height所以这也包括border你的元素,它被设置为2px分别使你的元素64px成为height和width。
对于符号,我正在使用属性vertical-align,因为我只能看到一个垂直对齐的字符(你没有说,但技术上我可以假设你在寻找什么形状),或者你也可以使用,但你需要设置容器元素到+line-heightvertical-align: middle;display: table-cell;
演示
最后但并非最不重要的一点是,您应该将span标签嵌套在内圈内div。
.circle{
float: left;
position: relative;
width: 120px;
height: 120px;
border-radius: 50%;
border: 2px solid #DDD;
}
.inner{
text-align: center;
line-height: 60px;
position: absolute;
top: 50%;
margin-top: -31px;
left: 50%;
margin-left: -31px;
width: 60px;
height: 60px;
border-radius: 50%;
border: 2px solid #DDD;
}