【发布时间】:2015-04-07 02:27:19
【问题描述】:
我正在尝试在我正在开发的当前网站上支持各种像素比率。我还想确保我提供任何必需的浏览器前缀,以在合理范围内支持最广泛的设备/浏览器。此外,我尽可能使用 SVG,但我需要摄影图像的解决方案。理想情况下,我想提供:
- @1x 图像(像素比 1.0)
- @2x 图片(像素比 1.25+)
- @3x 图像(像素比为 2.25+)
- @4x 图像(像素比 3.25+)
我的问题是编写媒体查询以实现这一目标的最佳方法是什么?我主要担心的是我的论点对于我想要实现的目标是正确的。我会很感激你有任何建议或意见。目前我的代码如下:
/* @1x Images (Pixel Ratio 1.0) */
#dgst_shopping_bag {background-image:url(img/shopping_bag.png);}
/* @2x Images (Pixel Ratio of 1.25+) */
@media only screen and (-o-min-device-pixel-ratio: 5/4),
only screen and (-webkit-min-device-pixel-ratio: 1.25),
only screen and (min-device-pixel-ratio: 1.25),
only screen and (min-resolution: 1.25dppx) {
#dgst_shopping_bag {background-image:url(img/shopping_bag@2x.png);}
}
/* @3x Images (Pixel Ratio of 2.25+) */
@media only screen and (-o-min-device-pixel-ratio: 9/4),
only screen and (-webkit-min-device-pixel-ratio: 2.25),
only screen and (min-device-pixel-ratio: 2.25),
only screen and (min-resolution: 2.25dppx) {
#dgst_shopping_bag {background-image:url(img/shopping_bag@3x.png);}
}
/* @4x Images (Pixel Ratio of 3.25+) */
@media only screen and (-o-min-device-pixel-ratio: 13/4),
only screen and (-webkit-min-device-pixel-ratio: 3.25),
only screen and (min-device-pixel-ratio: 3.25),
only screen and (min-resolution: 3.25dppx) {
#dgst_shopping_bag {background-image:url(img/shopping_bag@4x.png);}
}
备选方案 1: 我一直在考虑使用 <picture> 标记来完成此操作。我知道您可以为不支持<picture> 的浏览器提供替代内容,这将是我在使用它时最关心的问题。你们认为这将是提供多像素比例照片的最佳做法吗?
【问题讨论】:
-
小问题:您的图片在所有设备上的宽度都相同吗?
-
对于大多数设备,图像尺寸是相同的。我只是将资产换成高像素密度显示器。但是对于较低的断点,由于屏幕尺寸的限制,一些图像的尺寸较小。
标签: image css media-queries retina-display