Scale a rectangle in html and css

不打扰是莪最后的温柔 提交于 2019-12-12 03:33:41

问题


I want to make a rectangle (a div) with a specific scale. The height-width scale has to be 30:50. The rectangle fills 40% of the width-screen. If I resize my screen, how can I change the height if you keep the scale in mind?

HTML:

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

CSS:

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

回答1:


Try scaling it using vw (viewport width):

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

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



来源:https://stackoverflow.com/questions/42399453/scale-a-rectangle-in-html-and-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!