简体   繁体   English

如何响应性地缩小行中元素之间的空白

[英]How do I responsively shrink white space between elements in a row

Given the design below where the green bits are white space that can resize and the mountains are fixed size images that can not change size. 给定以下设计,其中绿色位是可以调整大小的空白区域,而山是固定大小的图像,不能更改大小。 How can I code this so that it will responsively resize (no javascript). 我该如何编码,以便它可以响应地调整大小(没有javascript)。

在此处输入图片说明

The initial widths of both the white space and the images are all different. 空白区域和图像的初始宽度都不同。

The green spaces need to scale down proportionally so that when one green space is 50% of its origional width all green spaces are 50% of their origional width. 绿地需要按比例缩小,以便当一个绿地为其原始宽度的50%时,所有绿地均为其原始宽度的50%。

Not use a flexbox. 不使用Flexbox。 Needs further back compatability. 需要进一步的向后兼容性。

This is what it would look like after half the green space has gone. 这是一半的绿色空间消失后的样子。

在此处输入图片说明

Consider giving each image its own % -based margin-right after declaring its width : 在声明其width后,考虑为每个图像赋予其基于%margin-right

 div { white-space:nowrap; } img { height: 120px; } img:nth-of-type(1) { width: 126px; margin-left:3%; margin-right:2%; } img:nth-of-type(2) { width: 168px; margin-right:1%; } img:nth-of-type(3) { width: 84px; margin-right:6%; } img:nth-of-type(4) { width: 28px; margin-right:3%; } img:nth-of-type(5) { width: 42px; margin-right:2%; } 
 <div> <img src="https://images.pexels.com/photos/29426/pexels-photo-29426.jpg" alt="Mountains" /> <img src="https://images.pexels.com/photos/29426/pexels-photo-29426.jpg" alt="Mountains" /> <img src="https://images.pexels.com/photos/29426/pexels-photo-29426.jpg" alt="Mountains" /> <img src="https://images.pexels.com/photos/29426/pexels-photo-29426.jpg" alt="Mountains" /> <img src="https://images.pexels.com/photos/29426/pexels-photo-29426.jpg" alt="Mountains" /> </div> 


NB I was initially going to suggest using CSS viewport width units ( vw ) rather than % . 注意:我最初会建议使用CSS视口宽度单位( vw )而不是%

But I see MDN states: 但我看到MDN指出:

Only Gecko-based browsers are updating the viewport values dynamically, when the size of the viewport is modified (by modifying the size of the window on a desktop computer or by turning the device on a phone or a tablet). 修改视口大小时(通过修改台式计算机上的窗口大小或通过在手机或平板电脑上打开设备),只有基于Gecko的浏览器会动态更新视口值。

See: http://developer.mozilla.org/en/docs/Web/CSS/length#Viewport-percentage_lengths 参见: http : //developer.mozilla.org/en/docs/Web/CSS/length#Viewport-percentage_lengths

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

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