css - 带文字的圆圈

标签 css

我将如何做出“是!!!”以下代码中的文本显示在圆圈的中心?

我试过添加内边距,但它只是将文本向右移动,也就是说,内边距没有在所有方向上均匀应用。

这是我的代码(http://jsfiddle.net/yxVkk/646/)

HTML:-

<div id="big-circle" class="circle big">
<div class="circle one"><span style="top: -50px;">YES!!!</span></div>
<div class="circle two"></div>
<div class="circle three"></div>
<div class="circle four"></div>
<div class="circle five"></div>
<div class="circle six"></div>
</div>

CSS:-

.circle {
    border-radius: 50%;
    width: 100px;
    height: 100px;
    background-color: red;
    display: inline-block;
    position: absolute;
}

.circle.big {
    width: 150px;
    height: 150px;
    background-color: blue;
    margin: 100px;
    }

    .one {
    left: -100px;
    top: -100px;
    }

    .two {
    top: -60px;
    left: 50px;
    }

    .three {
    right: -25px;
    top: -25px;
}


    .four {
        left: -25px;
        bottom: -25px;
        }

        .five {
        bottom: -60px;
    left: 50px;
    }

    .six {
    right: -25px;
    bottom: -25px;
    }

注意:我更愿意在没有 JS 的情况下完成此操作,如上例所示。

最佳答案

删除 style="top: -50px;" 并添加

.one>span{
    display:block;
    width: 100%;
    line-height:20px;
    font-size: 20px;
    margin-top: 40px;
    text-align:center
}

fiddle :http://jsfiddle.net/yxVkk/648/

关于css - 带文字的圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24519525/

相关文章:

css - 如何让过滤器在嵌套的 SVG 上工作?

css - Angular 2动画高度属性 - 绑定(bind)时间

javascript - 如何使此代码更干? (滚动时播放多个 css 动画)

javascript - 点击图片移动到前面?

javascript - 如何在点击动画时更改 Angular 中的 css 样式

html - CSS:如何做出正确的布局?

html - 如何使用 Bootstrap 3.0 在移动视口(viewport)上居中 "btn-group btn-group-justified"

html - 粘性页脚不适用于绝对位置

html - 文本和按钮之间的间距相等

css - 不显示打印元素