当添加一个:before选择器时,在这个场景中,我试图插入一个Phone图标,以显示在.front-page-contact div之上。理想情况下,它将位于.front-page-contact div中文本的中心位置。
如何定位这个选择器以达到上述结果?
.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;
}截图:

发布于 2016-03-24 13:12:27
如果给h2 position: relative,则伪元素将完全定位到h2,而不是页面。很难在没有看到标记的情况下说出更多。
编辑:
改为:
.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;
}必要时调整左/顶
https://stackoverflow.com/questions/36200931
复制相似问题