首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >定位a:在选择器之前

问定位a:在选择器之前
EN

Stack Overflow用户
提问于 2016-03-24 13:06:18
回答 1查看 1.4K关注 0票数 3

当添加一个:before选择器时,在这个场景中,我试图插入一个Phone图标,以显示在.front-page-contact div之上。理想情况下,它将位于.front-page-contact div中文本的中心位置。

如何定位这个选择器以达到上述结果?

代码语言:javascript
复制
 .front-page-contact .widget:nth-of-type(1) {
    text-align: center;
 }

.front-page-contact {
    background-color: #00AFBE;
    padding: 20px 0;
}

.front-page-contact h2 {
    font-size: 26px;
    color: #fff;
    margin: 0;
    position: relative;
}

.front-page-contact h2:before {
    font-family: Ionicons;
    content: "\f4b8";
    font-size: 40px;
    background-color: tomato;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    padding: 20px;
    display: block;
    position: relative;
    line-height: 1em;
    margin: 0 auto;
}

截图:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-24 13:12:27

如果给h2 position: relative,则伪元素将完全定位到h2,而不是页面。很难在没有看到标记的情况下说出更多。

编辑:

改为:

代码语言:javascript
复制
.front-page-contact h2:before {
    font-family: Ionicons;
    content: "\f4b8";
    font-size: 40px;
    background-color: tomato;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    padding: 20px;
    display: block;
    position: absolute;
    line-height: 1em;
    left: calc(50% - 40px);
    top: -60px;
}

必要时调整左/顶

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36200931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档