【问题标题】:Create three vertical dots (ellipsis) inside a circle在一个圆圈内创建三个垂直点(省略号)
【发布时间】:2017-03-30 10:26:19
【问题描述】:

我想做一个圈<div>,像这张图:

我已经尝试过这段代码。

.discussion:after {
  content: '\2807';
  font-size: 1em;
  background: #2d3446;
  width: 20px;
  height: 20px;
  border-radius: 100px;
  color:white;
}
<div class="discussion"></div>

我怎样才能正确地做到这一点?

【问题讨论】:

  • 你不能用徽章,把三个点放在里面吗?
  • 根据 cmets 对 doppelgreener 的回答,“\2807 是一个盲文字符,代表 8 个点中的 3 个点被填充。不能保证外观一致,因为有时它会显示其他(空)8 个点。它的右侧也有空白区域……您应该使用 \22EE,这是 Unicode 的实际垂直省略号字符。”。
  • 为了节省时间和增加灵活性,您应该只使用图标字体; for example(或make your own)。这是一个只使用一个特定图标的罕见网站。
  • 为什么不用 SVG? It's what GitHub uses.

标签: html css


【解决方案1】:

使用文本点

.discussion{
  width:50px;
  height:50px;
  text-align:center;
  background-color:black;
  border: 2px solid red;
  border-radius: 100%;
}
.discussion text{
  writing-mode: tb-rl;
  margin-top:0.4em;
  margin-left:0.45em;
  font-weight:bold;
  font-size:2em;
  color:white;
}
<div class="discussion"><text>...</text></div>

【讨论】:

    【解决方案2】:

    另一个答案,除了:

    • 它使用垂直省略号字符 (U+22EE)
    • 文本对齐和行高使内容居中
    • 不使用任何像素值

    .discussion:after {
      content: "\22EE";
      /* box model */
      display: inline-block;
      width: 1em;
      height: 1em;
      /* decoration */
      color: #FFFFFF;
      background-color: #000000;
      border-radius: 50%;
      /* center align */
      line-height: 1;
      text-align: center;
    }
    <div class="discussion"></div>
    <div class="discussion" style="font-size: 2em;"></div>
    <div class="discussion" style="font-size: 3em;"></div>
    <div class="discussion" style="font-size: 4em;"></div>

    请注意,U+2807 实际上是盲文图案并且点不应该居中。

    【讨论】:

      【解决方案3】:

      改进Nenad Vracar's answer,这是一个不使用文本(因此它与字体无关)并且一切都很好地居中:

      div {
        position: relative;
        background: #3F3C53;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        box-shadow: 0px 0px 15px 1px #4185BC;
        margin: 50px;
      }
      div:after {
        content: '';
        position: absolute;
        left: 50%;
        top: 50%;
        width: 2px;
        height: 2px;
        margin-left: -1px;
        margin-top: -1px;
        background-color: white;
        border-radius: 50%;
        box-shadow: 0 0 0 2px white, 0 11px 0 2px white, 0 -11px 0 2px white;
      }
      &lt;div&gt;&lt;/div&gt;

      【讨论】:

      • 这是对多个阴影的巧妙使用。如果您可以通过使用“em”而不是“px”来使其可扩展,那就更好了
      【解决方案4】:

      我已经删除(我找到了怎么做)我所有的帖子,下面的代码适用于 3 个垂直点进入一个黑色圆圈

      .discussion:after{
        display:inline-block;
        content:'\22EE';
        line-height:100%;
        border-radius: 50%;
        margin-left:10px;
        /********/
        font-size: 1em;             
        background: #2d3446;
        width: 20px;
        height: 20px;
        color:white;
      }
      &lt;div class="discussion"&gt;&lt;/div&gt;

      【讨论】:

      • 我已将您的代码转换为代码 sn-p。您有对齐问题 - 3 个点未居中。
      【解决方案5】:

      您可以将:after 伪元素与content: '•••' 和transform: rotate 一起使用。请注意,这是the bullet HTML special character•,或\u2022。

      div {
        position: relative;
        background: #3F3C53;
        width: 50px;
        height: 50px;
        color: white;
        border-radius: 50%;
        box-shadow: 0px 0px 15px 1px #4185BC;
        margin: 50px;
      }
      div:after {
        content: '•••';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) rotate(90deg);
        font-size: 15px; 
        letter-spacing: 4px;
        margin-top: 2px;
      }
      &lt;div&gt;&lt;/div&gt;

      【讨论】:

      • 你能让点居中吗?它们看起来略微向下和向右移动。
      • 我用• bullet char 更新了我的答案,它看起来不错(我在 Firefox 和 chrome 上测试过),一些反馈会很有帮助。
      • 在我的机器上它以 chrome (54) 为中心,但不在 Firefox (50) 上
      【解决方案6】:

      使用此代码。

      .discussion {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        position: relative;
        background: #2d3446;
      }
      
      .discussion:after {
        content: '\22EE';
        font-size: 1em;
        font-weight: 800;
        color: white;
        position: absolute;
        left: 7px;
        top: 1px;
      }
      &lt;div class="discussion"&gt;&lt;/div&gt;

      希望这会有所帮助!

      【讨论】:

      • 它可能与浏览器/操作系统/字体相关,但对我来说,圆点不会出现在圆圈的中间,它们会出现在右侧太多。 left: 0; top: 0; right: 0; text-align: center; 有意义并使其正确显示。
      • 对我来说(MSW 7 上的 Firefox 50 64 位)它们水平居中,但位于底部。
      • 如果你想将它们放在垂直和水平的中心,那么只需添加这些 css 属性 {left: 50%;最高:50%;变换:翻译(-50%,-50%);}。希望这会有所帮助,
      • 不会将边距设置为自动居中元素吗?
      • @sinthia: 只需将 :after 元素设置为 margin: auto 不会将其置于中心,因为我们已经给出了绝对位置。如果你想在 :after 中使用 margin: auto,那么你需要做的就是从 :after 中删除绝对、顶部、左侧元素并添加 margin: auto。您还需要在主 div 容器中添加 display:flex。
      【解决方案7】:

      我希望这是你想要的!否则请随时询问。

      .discussion{
        display: block;    /* needed to make width and height work */
        background: #2d3446;
        width: 25px;
        height: 25px;
        border-radius: 100px;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      
      .discussion:after {
        content: '\2807';
        font-size: 1em; 
        color: white;
        margin-left: 15%;
      }
      &lt;div class="discussion"&gt;&lt;/div&gt;

      【讨论】:

      【解决方案8】:

      .discussion:after {
        content: '\2807';
      font-size: 1em;
      display: inline-block;
      text-align: center;
      background: #2d3446;
      width: 20px;
      height: 20px;
      border-radius: 50%;
      color: white;
       padding:3px;
      }
      &lt;div class="discussion"&gt;&lt;/div&gt;

      【讨论】:

      • 我想在圆心上放 3 个点。我试过text-align:center。但它没有工作
      • 居中。我认为\2807 的内容在侧面有一些空间
      • \2807 在侧面有空格,因为it is a Braille character 并且应该在右侧有空格(或空点)。您应该使用\22EE,即unicode's vertical ellipsis character。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-19
      • 2021-07-27
      • 2013-08-08
      • 2012-11-12
      • 1970-01-01
      • 1970-01-01
      • 2020-06-14
      相关资源
      最近更新 更多