gpt4 book ai didi

html - 在 html 和 css 中缩放矩形

转载 作者:太空宇宙 更新时间:2023-11-04 09:06:42 24 4
gpt4 key购买 nike

我想制作一个具有特定比例的矩形 (div)。高宽比例必须为 30:50。矩形填充屏幕宽度的 40%。如果我调整屏幕大小,如果您牢记比例,我该如何更改高度?

HTML:

<div id="bg">   
</div>

CSS:

#bg {
background-color: blue;
width: 40%;
}

最佳答案

尝试使用 vw(视口(viewport)宽度)缩放它:

#bg {
background-color: blue;
width: 40vw;
height: 66.67vw;
}

https://jsfiddle.net/gmsitter/9tpbq30x/1/

关于html - 在 html 和 css 中缩放矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42399453/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com