简体   繁体   English

在 css 中的图像上覆盖字体真棒图标

[英]Overlaying a font-awesome icon on an image in css

I tried to overlay a font-awesome icon on an image, but the image is visible and the icon is not visible.我试图在图像上覆盖一个很棒的字体图标,但是图像是可见的,而图标是不可见的。

<i class="fa fa-play-circle-o" aria-hidden="true"></i>
<img src="../images/tbt.jpg"></img>

i {
   position: absolute;
   z-index: 1;
   top: 50%;
   left: 50%;
}
img {
   position: relative;
   z-index: -1;
}

You can add opacity in style您可以在样式中添加不透明度

i {
position: absolute;
z-index: 1;
top: 50%;
left: 50%;
opacity: 0;
}
img {
position: relative;
z-index: -1;
}
i:hover {
opacity: 1;
}

you did not mention the parent position.你没有提到父 position。 wrap both inside a any block tag like div, section and assign style position relative to this block level tag.将两者包装在任何块标签内,如 div、section 并相对于该块级标签分配样式 position。

<div style="position:relative">
<i class="fa fa-play-circle-o" aria-hidden="true"></i>
<img src="../images/tbt.jpg"></img>
</div>
i {
   position: absolute;
   z-index: 1;
   top: 50%;
   left: 50%;
}
img {
   position: relative;
   z-index: -1;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM