[英]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.您可以使用
vh
和vw
单位来实现这一点。 '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.