简体   繁体   English

响应式设计:针对不同屏幕尺寸的不同图像

[英]Responsive design: different images for different screen sizes

Our client wants to have a different banner image on smaller screens than on larger screens. 我们的客户希望在较小的屏幕上拥有与在较大屏幕上不同的横幅图像。 Not just shrink/stretch to fit, but actually substitute a different image. 不仅缩小/拉伸以适合,而且实际上替换不同的图像。 The full-size image is fairly complex -- several people, two logos, and some decorative text -- and so for the smaller image they want to crop out some of the people, drop the logos, etc. So they want the biggest, most complex image for desktops, a smaller simpler image for mid-size devices, and then smaller and simpler still for the smallest. 全尺寸图像相当复杂 - 有几个人,两个徽标和一些装饰性文字 - 因此对于较小的图像,他们想要裁剪一些人,删除徽标等。所以他们想要最大的,桌面最复杂的图像,中型设备的图像更简单,然后更小,更简单的图像。

What is the best way to do this? 做这个的最好方式是什么?

My first thought is to include all three images, and use @media min/max widths to make two of them invisible at any given size. 我的第一个想法是包括所有三个图像,并使用@media min / max widths使其中两个在任何给定大小都不可见。 Like: 喜欢:

@media (max-width: 400px) { .smallimg {display: block} .midimg {display: none} .bigimg {display: none} }
@media (min-width: 401px) and (max-width: 700px)  { .smallimg {display: none} .midimg {display: block} .bigimg {display: none} }
@media (min-width: 701px)  { .smallimg {display: none} .midimg {display: none} .bigimg {display: block} }

This ought to work but it would download all three images every time, which seems rather a waste of bandwidth. 这应该工作,但每次都会下载所有三个图像,这似乎是浪费带宽。

I could change the images from img tags to css background images. 我可以将图像从img标签更改为css背景图像。 Would that be better? 会更好吗? Would that avoid downloading all three or would it still do that? 这会避免下载这三个还是仍然会这样做?

I was thinking of writing some JavaScript to dynamically update the URL in the img tag based on the screen size, but that seems like a bunch of complexity. 我正在考虑编写一些JavaScript来根据屏幕大小动态更新img标签中的URL,但这似乎是一堆复杂性。

I briefly thought of making the logos and text separate images and breaking the actual picture into pieces and then trying to assemble them all as overlapping images. 我简要地想过将徽标和文本分开并将实际图片分成几块,然后尝试将它们全部组合成重叠图像。 But that sounds like a lot of work to get right, and then I'd have to make sure it looks right at all possible sizes, not so easy to just shrink or stretch, etc. And while it's probably do-able in this particular case, I'd prefer a general solution that I can use in the future. 但这听起来似乎要做很多工作,然后我必须确保它看起来正确的尺寸,不是那么容易缩小或拉伸等等。虽然它可能在这个特定的我希望将来可以使用一般的解决方案。

Anybody done something like this and have some ideas about the best way to do it? 有人做过类似这样的事情并对最好的方法有一些想法吗?

you may use css background in media queries . 您可以在media queries使用css background The images are only loaded if the CSS requires it to be, so if nothing matches the selector then it won't bother loading the image. 只有在CSS要求的情况下才会加载图像,因此如果没有任何东西与选择器匹配,那么它就不会打扰加载图像。

This article will surely help you. 这篇文章肯定会对你有所帮助。

I would checkout Zurb Foundation's Interchange for handling responsive images. 我会检查Zurb Foundation的Interchange来处理响应式图像。 The best cross browser approach i have found. 我发现了最好的跨浏览器方法。

http://foundation.zurb.com/docs/components/interchange.html http://foundation.zurb.com/docs/components/interchange.html

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

相关问题 响应式 canvas 内容以适应不同的屏幕尺寸 - Responsive canvas content to fit different screen sizes 带有不同尺寸图像的自适应图像列表 - responsive image list with images in different sizes 将html / css图片缩放为不同的屏幕尺寸? - Scaling html/css images for different screen sizes? 如何针对不同尺寸的图片进行响应式设计? - How to make responsive design for different size images? 在响应式设计中固定不同尺寸的元件之间的间距 - Fixed spacing between elements of different sizes in a responsive design 使用attr()以响应方式在不同的屏幕尺寸上显示不同的背景图像 - Responsively show different background images on different screen sizes using attr() 如何使我的块引用响应不同的屏幕尺寸? - How do i make my blockquote responsive to different screen sizes? Twitter Bootstrap响应式图像具有不同大小调整大小不一致 - Twitter Bootstrap responsive images with different sizes resizing unproportionaly 如何设置具有不同引导响应大小的图像中的最大宽度? - How to set the maximum width in images with different bootstrap responsive sizes? 自适应div和图片,其中图片的大小不同 - Responsive div and image, where images have different sizes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM