回答
這裏有一個demo on JSFiddle和一個片段:
.numberCircle {
border-radius: 50%;
behavior: url(PIE.htc);
/* remove if you don't care about IE8 */
width: 36px;
height: 36px;
padding: 8px;
background: #fff;
border: 2px solid #666;
color: #666;
text-align: center;
font: 32px Arial, sans-serif;
}
<div class="numberCircle">30</div>
爲了使這項工作在IE8 and older,您必須下載並使用CSS3 PIE。我上面的演示在IE8中不起作用,但那只是因爲jsFiddle沒有託管PIE.htc
。
可以使用邊界半徑爲這樣:
<html>
<head>
<style type="text/css">
.round
{
-moz-border-radius: 15px;
border-radius: 15px;
padding: 5px;
border: 1px solid #000;
}
</style>
</head>
<body>
<span class="round">30</span>
</body>
</html>
播放與邊框半徑和填充值,直到您滿意的結果。
但這不適用於所有瀏覽器。我想IE仍然不支持圓角。
不要在你的CSS
div { width: 10em; height: 10em; -webkit-border-radius: 5em; -moz-border-radius: 5em; } p { text-align: center; margin-top: 4.5em; }
使用段落標籤寫的文字是這樣的。希望幫助
你像一個標準塊的工作,這是一個方形
.circle {
width: 10em; height: 10em;
-webkit-border-radius: 5em; -moz-border-radius: 5em;
}
這是CSS 3的功能,它是不是很好suporrted,你可以指望Firefox和Safari是肯定的。
<div class="circle"><span>1234</span></div>
如果是20,下,您可以只使用Unicode字符①②...⑳
這裏我的解決方案 - 這很容易地允許不同大小和顏色關係進入一個用於編輯控制的CMS。 IE降級爲正方形。
HTML:
<div class="circular-label label-outer label-size-large label-color-pink">
<div class="label-inner">
<span>Fashion & Beauty</span>
</div>
</div>
CSS:
.circular-label {
overflow: hidden;
z-index: 100;
vertical-align: middle;
font-size: 11px;
-webkit-box-shadow:0 3px 3px rgba(0, 0, 0, 0.2);
-moz-box-shadow:0 3px 3px rgba(0, 0, 0, 0.2);
box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.2);
}
.label-inner {
width: 85%;
height: 85%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
border: 2px dotted white;
vertical-align: middle;
margin: auto;
top: 5%;
position: relative;
overflow: hidden;
}
.label-inner > span {
display: table;
text-align: center;
vertical-align: middle;
font-weight: bold;
text-transform: uppercase;
width: 100%;
position: absolute;
margin: auto;
margin-top: 38%;
font-family:'ProximaNovaLtSemibold';
font-size: 13px;
line-height: 1.0em;
}
.circular-label.label-size-large {
width: 110px;
height: 110px;
-moz-border-radius: 55px;
-webkit-border-radius: 55px;
border-radius: 55px;
margin-top:-55px;
}
.circular-label.label-size-med {
width: 76px;
height: 76px;
-moz-border-radius: 38px;
-webkit-border-radius: 38px;
border-radius: 38px;
margin-top:-38px;
}
.circular-label.label-size-med .label-inner > span {
margin-top: 33%;
}
.circular-label.label-size-small {
width: 66px;
height: 66px;
-moz-border-radius: 33px;
-webkit-border-radius: 33px;
border-radius: 33px;
margin-top:-33px;
}
這不是太難看如何做到這一點。更大的問題是,是否有可能使圓形標尺的尺寸達到內容。
目前我不認爲這是可能的。任何人?
喜歡的東西我做了什麼here可以工作(對數字0〜99):
CSS:
.circle {
border: 0.1em solid grey;
border-radius: 100%;
height: 2em;
width: 2em;
text-align: center;
}
.circle p {
margin-top: 0.10em;
font-size: 1.5em;
font-weight: bold;
font-family: sans-serif;
color: grey;
}
HTML:
<body>
<div class="circle"><p>30</p></div>
</body>
問題大多數其他答案在這裏是你需要調整外部容器的大小o它是基於字體大小和要顯示的字符數量的完美大小。如果你混合了1位數字和4位數字,它將不起作用。如果字體大小和圓形大小之間的比例不完美,則最終會在大圓的頂部垂直對齊一個橢圓形或小數字。這應該適用於任何數量的文本和任何大小的圓圈。只需設定width
和line-height
相同的值:
.numberCircle {
width: 120px;
line-height: 120px;
border-radius: 50%;
text-align: center;
font-size: 32px;
border: 2px solid #666;
}
<div class="numberCircle">1</div>
<div class="numberCircle">100</div>
<div class="numberCircle">10000</div>
<div class="numberCircle">1000000</div>
如果你需要使內容或長或短,所有你需要做的是調整容器的寬度美好適合。
提高第一個答案剛剛擺脫填充,並添加line-height
和vertical-align
:
.numberCircle {
border-radius: 50%;
width: 36px;
height: 36px;
line-height: 36px;
vertical-align:middle;
background: #fff;
border: 2px solid #666;
color: #666;
text-align: center;
font: 32px Arial, sans-serif;
}
對於圈子的大小不同而不同基礎上的內容可以這樣:
<span class="numberCircle"><span>30</span></span>
<span class="numberCircle"><span>1</span></span>
<span class="numberCircle"><span>5435</span></span>
<span class="numberCircle"><span>2</span></span>
<span class="numberCircle"><span>100</span></span>
.numberCircle {
display:inline-block;
line-height:0px;
border-radius:50%;
border:2px solid;
font-size:32px;
}
.numberCircle span {
display:inline-block;
padding-top:50%;
padding-bottom:50%;
margin-left:8px;
margin-right:8px;
}
它依靠內容的寬度加上margin-
來確定半徑,然後使用padding-
的高度來擴展高度。 margin-
需要根據字體大小進行調整。
更新以除去內部元件:
<span class="numberCircle">30</span>
<span class="numberCircle">1</span>
<span class="numberCircle">5435</span>
<span class="numberCircle">2</span>
<span class="numberCircle">100</span>
<style type="text/css">
.numberCircle {
display:inline-block;
border-radius:50%;
border:2px solid;
font-size:32px;
}
.numberCircle:before,
.numberCircle:after {
content:'\200B';
display:inline-block;
line-height:0px;
padding-top:50%;
padding-bottom:50%;
}
.numberCircle:before {
padding-left:8px;
}
.numberCircle:after {
padding-right:8px;
}
</style>
使用僞元素強制高度。需要用於垂直對齊的零寬度空間。將line-height:0px
從外部移動到僞,以便在降級IE8時至少可見。
thirtydot的答案是正確的,但缺少一點。您需要添加職位:相對,如果您想在圓圈中居中取值幷包含不同範圍的號碼。 例如123;
HTML:
<div class="numberCircle">30</div>
CSS:
.numberCircle {
border-radius: 50%;
behavior: url(PIE.htc); /* remove if you don't care about IE8 */
width: 36px;
height: 36px;
padding: 8px;
position: relative;
background: #fff;
border: 2px solid #666;
color: #666;
text-align: center;
font: 32px Arial, sans-serif;
}
而是最簡單的解決方法是使用引導
<span class="badge" style ="float:right">123</span>
最簡單的方法是使用引導和徽章類
<span class="badge">1</span>
此版本不依賴於硬編碼的,固定的值,但尺寸相對於div
的font-size
。
CSS:
.numberCircle {
font: 32px Arial, sans-serif;
width: 2em;
height: 2em;
box-sizing: initial;
background: #fff;
border: 0.1em solid #666;
color: #666;
text-align: center;
border-radius: 50%;
line-height: 2em;
box-sizing: content-box;
}
HTML:
<div class="numberCircle">30</div>
<div class="numberCircle" style="font-size: 60px">1</div>
<div class="numberCircle" style="font-size: 12px">2</div>
HTML實例
<h3><span class="numberCircle">1</span> Regiones del Interior</h3>
CODE
.numberCircle {
border-radius:50%;
width:40px;
height:40px;
display:block;
float:left;
border:2px solid #000000;
color:#000000;
text-align:center;
margin-right:5px;
}
- 1. 用css圍繞圓圈文字
- 2. 無法使用CSS圓圈
- 3. 圓圈鍵CSS
- 4. CSS/HTML - 圓圈數字的水平線
- 5. 如何使一個圓圈,並使用CSS
- 6. 如何用中間的數字創建一個圓圈,以適應HTML/CSS中的圓圈?
- 7. 如何用盡可能小的圓形區域圍繞文字製作圓圈?
- 8. 如何在CSS中製作大圓圈內的圓圈以及所有圓圈中心內的文字?
- 9. 如何使用CSS將圓圈中的「加號」完美居中
- 10. 我可以使用HTML&CSS來包裝文字通過一個圓圈
- 11. 在圓圈周圍繪製文字
- 12. 使用CSS在圓圈內創建圓形
- 13. cv:圓圈函數用一次調用繪製多個圓圈
- 14. 用CSS製作透明圓圈
- 15. 用CSS畫出圓圈的半徑線
- 16. 用css和jquery圓圈動畫
- 17. CSS裝飾 - 填寫字母的圓圈
- 18. 如何使用KineticJS從一個圓圈創建箭頭到另一個圓圈?
- 19. CSS中的圓圈交點
- 20. CSS A圓圈和發光
- 21. 與一些CSS圓圈
- 22. 圍繞一個大圓圈移動一個小圓圈
- 23. 在iOS中添加多個圍繞着圓圈的圓圈
- 24. CSS:位置圓(LI)成一個圓圈
- 25. 如何使用開羅將文字保留在圓圈內?
- 26. 如何漸變背景適用於HTML CSS圓圈DIV
- 27. 圈在使用CSS
- 28. 如何用x標記繪製圓圈?
- 29. D3 - 圓圈包裝多個數據
- 30. 用於在圓圈周圍繪製小線條的數學
當前最新版本的Internet Explorer,9,實際上支持border-radius。 ...和div不是這個的好選擇。 :) – reisio 2012-04-25 03:15:51
display:inline-block; – Kirkland 2013-06-10 18:29:05
要使它在小提琴中工作,您可以針對CDN,例如[jsdelivr](http://www.jsdelivr.com/#!css3pie),而不是使用URL的相對路徑。如果你用`// cdn.jsdelivr.net/css3pie/2.0b1/PIE.htc`更新你的小提琴中的URL,它應該可以在任何地方工作,而無需額外的重組工作。 – KyleMit 2014-01-06 16:46:19