【问题标题】:Circle around :before element环绕 :before 元素
【发布时间】:2014-01-12 10:34:39
【问题描述】:

您好,我正在尝试找出与此线程 How to use CSS to surround a number with a circle? 中提出的问题相同的问题

但是 - 每次我这样做时,形状都会变成椭圆形,无论我是否添加宽度/高度......

我在这里创建了一个 jsfiddle http://jsfiddle.net/dDuFv/

<ul class="numberCircle">
    <li>testing</li>
    <li>testing</li>
    <li>testing</li>
</ul>

CSS

.numberCircle { list-style-type:none; font-size:18px; }
.numberCircle li { margin:20px;}
.numberCircle li:before {
    border-radius:100%;
    counter-increment: section;
    content:counter(section);
    background: #f1562c;
    color:#fff;
    padding:2px;
    border:none;
    text-align: center;
}

但它只是不工作!

感谢您的帮助!

【问题讨论】:

    标签: geometry css


    【解决方案1】:

    给伪类display:inline-block;。它应该可以工作。

    写:

    .numberCircle li:before {
        width:20px;
        display:inline-block;
    }
    

    Updated fiddle here.

    【讨论】:

    • 很棒的答案,但为什么需要这样做才能使其正常运行?只是好奇
    • 谢谢,因为默认情况下,伪元素是内联的,高度、宽度、边距等属性不适用于inline 元素。
    • 嗯,现在很难让文本在圆圈中居中,有什么想法吗?感谢之前的回答!
    • @Matt 欢迎 :) 文本不是居中吗?你可以写text-align:center
    • 没关系,它工作,由于某种原因,即使我有相同的代码复制你的 jsfiddle 工作..我相信..
    猜你喜欢
    • 1970-01-01
    • 2016-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-14
    • 2019-06-23
    • 2012-01-21
    相关资源
    最近更新 更多