首先,使用margin: auto;
是不黑客攻擊
並以圓心內你的圈子,你可以使用定位技術,如position: absolute;
。在這裏,我的內圓用position: absolute;
,比正與的50%
一個值分配top
和left
性質和比正在使用margin-top
和margin-left
和扣除height
和width
的1/2。
爲什麼要扣除32px
?正如我已經說過我正好在扣除總額的一半width
和height
所以這也包括設置爲2px
,這使得您在height
和width
元素64px
分別您元素的border
。
要vertical-align
的+
符號,現在用line-height
財產,我只能看到單個字符垂直對齊(你沒有說,但在技術上我可以假設你在找什麼形狀的),或者你也可以使用vertical-align: middle;
但你需要的容器元素設置爲display: table-cell;
Demo
最後但並非最不重要的,你應該巢內圓內span
標籤。
.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;
}
爲什麼不'保證金auto'? – Praveen
是否具有固定大小的元素?總是120px和60px? –
哪一部分你想在中心? 「+」號或內圈還是兩者? – Hiral