看看documentation for retina.js on GitHub。向下滚动到描述 SASS、SCSS 和 LESS 的部分。在这些下方,您将看到 CSS 是如何呈现的。你没有提到你是否使用任何预处理器,但如果你是,我在下面引用该网站:
SCSS
#item {
@include retina('/images/my_image.png', 3, cover, center center no-repeat);
}
萨斯
#item
+retina('/images/my_image.png', 3, cover, center center no-repeat)
少
#item {
.retina('/images/my_image.png', 3, cover, center center no-repeat);
}
手写笔
#item
retina('/images/my_image.png', 3, cover, center center no-repeat)
不管是什么方言,输出实际上都是一样的:
#item {
background: url("/images/my_image.png") center center no-repeat;
background-size: cover;
}
@media all and (-webkit-min-device-pixel-ratio: 1.5),
all and (-o-min-device-pixel-ratio: 3 / 2),
all and (min--moz-device-pixel-ratio: 1.5),
all and (min-device-pixel-ratio: 1.5) {
#item {
background: url("/images/my_image@2x.png") center center no-repeat;
background-size: cover;
}
}
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
#item {
background: url("/images/my_image@2x.png") center center no-repeat;
background-size: cover;
}
}
@media (-webkit-min-device-pixel-ratio: 3), (min-resolution: 288dpi) {
#item {
background: url("/images/my_image@3x.png") center center no-repeat;
background-size: cover;
}
}