多尺度视网膜图像增强_具有图像设置的高效视网膜背景

多尺度视网膜图像增强

While illustrative images are now well-served in HTML5 and CSS with regards to high-DPI displays, with broad browser support for the picture element, srcset and sizes, Retina background images have been largely neglected during these advances. As background images are often quite large (in both pixel count and file size), this is particularly bothersome. While there has been an intermediate solution available for a long time, there’s now an even better one.

同时说明图像是现在服务良好HTML5CSS至于高DPI显示器 ,与广泛的浏览器支持picture元素srcsetsizes ,视网膜背景图片已经在很大程度上这些进展中被忽视。 由于背景图像通常很大(像素数和文件大小都很大),因此特别麻烦。 尽管存在很长一段时间的中间解决方案,但现在有了更好的解决方案。

@media解决方案 (@media Solutions)

A high-DPI image can be used on the appropriate screens using a @media query, as discussed in the previous article. Given an ordinary 72DPI image named automobile.jpg with a high-resolution version named automobile-2x.jpg, we can switch between the two being applied to the <body> with:

如上一篇文章所述,可以使用@media查询在适当的屏幕上使用高DPI图像。 给出一个普通的图像72DPI名为automobile.jpg具有高分辨率版本名为automobile-2x.jpg ,我们可以被施加到在两者之间切换<body>用:

body {
    background-image: url("automobile.jpg");
    background-size: cover;
}

@media (-webkit-min-device-pixel-ratio: 2), 
(min-resolution: 192dpi) { 
    body {
        background-image: url("automobile-2x.jpg");
    }
}

图像集 (image-set)

A more concise and efficient method can be used with image-set. Because it is only currently supported in Webkit-derived browsers, it requires an approximate vendor prefix:

可以对image-set使用更简洁有效的方法。 因为它仅在Webkit派生的浏览器中当前受支持 ,所以它需要一个近似的供应商前缀

body {
    background-image: url("automobile.jpg");
    background-image: -webkit-image-set(url("automobile.jpg") 1x, url("automobile-2x.jpg") 2x );
    background-size: cover;
}

You might note that the syntax is very much like that for the x designator in srcset, used for ordinary responsive images.

您可能会注意到,语法非常类似于srcsetx指示符 (用于普通的响应图像)。

结论 (Conclusion)

image-set() is a promising method to use for Retina background images, but needs careful consideration: you can either use the now-traditional @media query to cover all browsers, or image-set() with a fallback, which will cover non-supporting browsers with a standard resolution image.

image-set()是用于视网膜背景图像的一种有前途的方法,但是需要仔细考虑:您可以使用现在传统的@media查询覆盖所有浏览器,也可以使用具有后备功能的image-set()来覆盖不支持标准分辨率图像的浏览器。

翻译自: https://thenewcode.com/1118/Efficient-Retina-Backgrounds-with-image-set

多尺度视网膜图像增强

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值