之前在做广告关闭效果都是通过一个大的盒子去包含一张设置百分百的图片来填充格子然后通过定位的手段做的然后我想省省代码干脆直接给img添加after伪元素通过叉号的字体图标给img设置相对定位伪元素设置绝对定位结果发现这个字体图标一直不显示不理解是为什么
这有个案例可以参考一下
html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Documenttitle>
<style>
@font-face {
font-family: 'icomoon';
src: url('fonts/icomoon.eot?d1ow8u');
src: url('fonts/icomoon.eot?d1ow8u#iefix') format('embedded-opentype'),
url('fonts/icomoon.ttf?d1ow8u') format('truetype'),
url('fonts/icomoon.woff?d1ow8u') format('woff'),
url('fonts/icomoon.svg?d1ow8u#icomoon') format('svg');
font-weight: normal;
font-style: normal;
font-display: block;
}
img {
position: relative;
}
img::after {
content: '';
width: 10px;
height: 10px;
position: absolute;
top: 0;
right: 0;
background-color: aqua;
display: inline-block;
}
style>
head>
<body>
<img src="/images/ad.jpg" alt="">
body>
html>
对于可替换元素(如 img、input、select 等),浏览器会有差异性。可能没有起效果