我想把一个数字围成一个圆,就像下图所示:

这可能吗?它是如何实现的?


当前回答

最简单的方法是使用bootstrap和badge类

 <span class="badge">1</span>

其他回答

三十点的答案是对的,但少了一点。你需要添加位置:相对,如果你想在圆中有居中值,还包括不同范围的数字。 例如123;

HTML:

< div级30 =“numberCircle > < / 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;
}

但最简单的解决方案是使用Bootstrap

<span class="badge" style ="float:right">123</span> .

你可以使用border-radius:

<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仍然不支持圆角。

我很惊讶没有人使用更容易理解的flex,所以我把我的答案放在这里:

要创建一个圆,请确保宽等于高 为了适应圆圈中数字的字体大小,请使用em而不是px 要将数字居中,请使用flex和justify-content: center;对齐项目:中心; 如果数字增加(例如>1000),则同时增加宽度和高度

这里有一个例子:

.circled-number { color: #666; border: 2px solid #666; border-radius: 50%; font-size: 1rem; display: flex; justify-content: center; align-items: center; width: 2em; height: 2em; } .circled-number--big { color: #666; border: 2px solid #666; border-radius: 50%; font-size: 1rem; display: flex; justify-content: center; align-items: center; width: 4em; height: 4em; } <div class="circled-number"> 30 </div> <div class="circled-number--big"> 3000000 </div>

对于0到99的数字来说,这样做是可行的:

.circle { 边框:0.1em纯灰色; 这个特性:100%; 高度:2 em; 宽:2 em; text-align:中心; } .circle p { margin-top: 0.10 em; 字体大小:1.5 em; 粗细:大胆的; 字体类型:无衬线; 颜色:灰色; } 身体< > < div class = "圆" > < p > < / p > 30 < / div > 身体< / >

在css中做这样的事情吗

 div {
    width: 10em; height: 10em; 
    -webkit-border-radius: 5em; -moz-border-radius: 5em;
  }
  p {
    text-align: center; margin-top: 4.5em;
  }

使用段落标签来书写文本。希望这能有所帮助