简体   繁体   English

CSS:如何根据屏幕/窗口大小设置宽度和高度?

[英]CSS: How to set the width and height dependent on the screen/window size?

Following up this question here I am trying to get a good rendering of a floating 3D cube using three.js. 这里跟进这个问题我试图使用three.js很好地呈现浮动3D立方体。 The camera proportions are window.innerWidth / window.innerHeight and since I am using a rectangular div container, I get a flattened cube. 相机比例为window.innerWidth / window.innerHeight ,由于我使用的是矩形div容器,因此得到了一个扁平的立方体。 Something like this . 这样的东西。

I tried to get my div container to be in proportion with my screen or window size and it worked! 我试图使我的div容器与我的屏幕或窗口大小成比例,并且可以正常工作! For example for a 1367x768 screen: 例如,对于1367x768屏幕:

CSS: CSS:

#render {
    width: 450px;
    height: 250px;
}

But! 但! I want to have this worked out also for different size, eg for smartphones too! 我也想针对不同的尺寸(例如智能手机)解决这个问题! It would be perfect to make this fully responsive. 使其完全响应将是完美的。 Is it possible to get the width and height fully proportional to the screen size in CSS? 是否有可能使宽度和高度与CSS中的屏幕尺寸完全成比例?

There are units displaying elements depending to the screen : vh and vw 根据屏幕的不同,有些单元显示元素:vh和vw

vh : means viewport height. vh:视口高度。

ie : height:50vh; 即: height:50vh; will take 50% height of the screen ( and not of the parent element ). 将占据屏幕高度的50%(而不是父元素的高度)。

vw : means viewport width. vw:表示视口宽度。

ie : width:50vw; 即: width:50vw; will take 50% width of the screen ( and not of the parent element ). 将占据屏幕宽度的50%(而不是父元素的宽度)。

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

相关问题 尝试将样式设置为屏幕高度和宽度CSS - Trying to set style as screen height and width CSS CSS,如何仅在第一页加载时将最小高度/宽度设置为屏幕高度/宽度? - CSS, How do I set the min-height/width to the screen height/width only on first page load? 缩小屏幕尺寸时如何在Css中使用响应设置重量和高度 - How to set weight and height in Css with responsive when reduce screen size 在页面加载之前将CSS img max-height + max-width属性动态设置为窗口大小吗? - Dynamically set CSS img max-height + max-width attribute to window size before page load? 如何在 Jssor 全宽 + 高度按窗口大小 - How to in Jssor full width + height by window size 如何根据浏览器的宽度动态设置表格宽度 window - How to set table-width dynamically, dependent on width of browser window 如何在JavaScript中按%(百分比)设置屏幕高度和宽度 - How to set the screen height and width by %(percentage) in javascript 如何设置背景尺寸(高度和宽度)? - How to set background size (height & width)? 是否可以将Canvas ID的width和height属性设置为窗口大小的90%? - Is it possible to set the width and height attributes of a Canvas ID to 90% of the window size? jquery找到img大小并设置为div css的高度和宽度 - jquery to find img size and set to div css height and width
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM