简体   繁体   English

随着视口宽度的变化,如何让所有 div 的高度缩小?

[英]How do I get all of my divs to shrink in height as the width of the viewport changes?

How do I get all of my divs to shrink in height as the width of the viewport changes?随着视口宽度的变化,如何让所有 div 的高度缩小?

Example: https://jenis.com/示例: https : //jenis.com/

When you reduce the width of this website, the heights of the divs reduce in height.当您缩小本网站的宽度时,div 的高度也会降低。

You use percentage based CSS.您使用基于百分比的 CSS。 For the main image, they are using the following tag to scale the background to the browser viewport:对于主图像,他们使用以下标签将背景缩放到浏览器视口:

background-size: 100% auto;

100% means the element's content area will equal exactly the explicit width of its parent, provided its parent has an explicit width. 100% 意味着元素的内容区域将完全等于其父元素的显式宽度,前提是其父元素具有显式宽度。

You can use vh and vw units to achieve this.您可以使用vhvw单位来实现这一点。 'vw' is the viewport width and 'vh` stands for viewport height. 'vw' 是视口宽度,'vh' 代表视口高度。

If you give height:50vw , the height of div will be directly proportional to the viewport width.如果您提供height:50vw ,则 div 的高度将与视口宽度成正比。

暂无
暂无

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

相关问题 3 DIV相同的高度。 用窗户收缩最左边的宽度和所有高度 - 3 DIVs same height. Shrink leftmost width and all heights with window 如何在JavaScript中获取浏览器视口的宽度和高度并将其应用于CSS ID? - How Do I Get Browser Viewport Width & Height In Javascript And Apply To CSS ID's? 如何获取浏览器视口的小数宽度和高度? - How to get the fractional width and height of the browser viewport? 如何在视口宽度减小的情况下将 a 从最大高度缩小到最小高度? - How to shrink a from a max-height to a min-height over the size decrease of the viewport width? 使用JavaScript使div的宽度和高度等于视口 - Make divs width and height equal to viewport with JavaScript 在响应式布局中,如何让 div 均匀收缩? - In a responsive layout how can I get divs to shrink uniformly? 如何通过视口width = device-width来获取用于加载清晰图像但正确设置字体/ div大小的设备分辨率? - How get device resolution for loading sharp images but size fonts/divs properly with viewport width=device-width? 获取不包括滚动条的视口的宽度和高度 - Get width and height of viewport excluding scroll bars 当视口/引导程序导航栏发生变化时,如何调整 Leaflet map 的大小? - How do I resize my Leaflet map when the viewport/ bootrap navbar changes? 当视口改变时,如何动态更新画布尺寸(实际像素)? - How do I dynamically update my canvas size (real pixels) when the viewport changes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM