我比较 sprite 中的所有图像,不决定哪个选项更好:
<img src="./img/sprite.png" height="63" width="193" class="sprite-class" alt="">
.sprite-class {
object-fit: none;
object-position: -440px -315px;
font-family: 'object-fit: none; object-position: -440px -315px;';
height: 63px;
width: 193px
}
还有一些用于IE的js代码
第二个选项:
<div class="sprite-class"></div>
.sprite-class {
background-position: -494px -20px;
width: 63px;
height: 193px;
background: url(./img/sprite.png) 0px 0px no-repeat;
margin: 0 auto;}
Last 在没有 js 的情况下在 IE 中工作,但是将 div 用于显示 Logo 和其他图像是否很好?感谢您的回答!
最佳答案
不,为了显示 Logo ,您不应该使用背景图片。这篇文章可能对你有帮助,When to use IMG vs. CSS background-image?
关于html - 实现 css Sprite 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39648424/