简体   繁体   English

是否可以在DIV背景图像标记中使用“响应式”图像?

[英]Is it possible to use 'responsive' images in/with a DIV background-image tag?

I'm looking to use a selection of Thumbnails that are loaded into my site from a database at different sizes (all within a Masonry grid) 我希望使用从数据库以不同大小(全部在Masonry网格内)加载到我的网站中的缩略图的选择

Normally I would simply use background-image:url(image.jpg); background-size: 100% 100%: 通常我只会使用background-image:url(image.jpg); background-size: 100% 100%: background-image:url(image.jpg); background-size: 100% 100%: but I'm trying to be a little more bandwidth conscious with specific image file sizes. background-image:url(image.jpg); background-size: 100% 100%:但是我正在尝试使用特定的图像文件大小来提高带宽意识。 I also want to target a specific crop for mobile browsers using a portrait orientation. 我还想使用纵向方向为移动浏览器定位特定的作物。

Is it possible to use the features of the <picture> , namely media="(min-width: 40em) and (orientation: portrait)" while using the background-image property? 在使用background-image属性时,是否可以使用<picture> ,即media="(min-width: 40em) and (orientation: portrait)"

Or should I instead use the img or picture tags? 还是应该改用imgpicture标签?

Use the image tag, along with media queries. 使用image标签以及媒体查询。 That will solve the problem and you will be able to send smaller versions in case a smaller picture size is needed. 这样可以解决问题,并且在需要较小图片尺寸的情况下,您可以发送较小的版本。 If bandwidth is of serious concern here, then you might consider to do media-queries only based on screen size. 如果带宽在这里非常重要,那么您可以考虑仅根据屏幕大小进行媒体查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM