Tom*_*m25 3 css icons css3 pseudo-element
添加:before选择器时,在这种情况下,我试图插入一个电话图标显示在.front-page-contactdiv 上方.理想情况下,它将居中于.front-page-contactdiv中的文本上方.
我怎么能定位这个选择器来实现上面提到的结果?
.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;
}
Run Code Online (Sandbox Code Playgroud)
截图:
给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;
}
Run Code Online (Sandbox Code Playgroud)
根据需要调整左/上