不同媒体设置不同类名;
不同类名添加伪元素,设置不同背景图片;
li{
&::before{
content:'';
position: absolute;
background: url('../../../static/images/douyin.png');
width: 36px;
height: 36px;
background-size: cover;
right: 0;
top:0;
}
}
.xiaohongshu{
&::before{
background: url('../../../static/images/xiaohongshu.png');
}
}
.weibo{
&::before{
background: url('../../../static/images/weibo.png');
}
}
.kuaishou{
&::before{
background: url('../../../static/images/kuaishou.png');
}
}
发现除了抖音媒体的图片能够正常显示,其余媒体的图片显示不正常;
正常样子

现在样子

background复合属性会覆盖backgroun-size属性!!!li{
&::before{
content:'';
position: absolute;
background: url('../../../static/images/douyin.png');
width: 36px;
height: 36px;
background-size: cover;
right: 0;
top:0;
}
}
.xiaohongshu{
&::before{
background: url('../../../static/images/xiaohongshu.png');
background-size: cover;
}
}
.weibo{
&::before{
background: url('../../../static/images/weibo.png');
background-size: cover;
}
}
.kuaishou{
&::before{
background: url('../../../static/images/kuaishou.png');
background-size: cover;
}
}
既然踩坑了,就再复习一下背景属性知识点吧!!
background-size
属性值
父盒子(本盒子)的高宽进行比例计算;小的一边将盒子完全盖住;大的一边将盒子完全盖住;注:背景图片不能撑大 盒子(也就是说若是盒子没有设置宽高,则可能造成背景图片不显示)
div {
background: rgba(255, 0, 0, 0.5)
url('./images/abcd.jpg') center no-repeat fixed;
background-size: 200px 200px;
}
<body>
<div>div>
body>
如上代码