5.1.2. Viewport-percentage lengths: the ‘vw’, ‘vh’, ‘vmin’, ‘vmax’ units
The viewport-percentage lengths are relative to the size of the
initial containing block. When the height or width of the initial
containing block is changed, they are scaled accordingly
****好的我觉得可以这么做的## 标题文字 ##
@黑色杜克 的css要在一定的条件下才会有用。条件就是.container的所有的parent element的height都应该赋值了。
假如有以下的html:
你的css应该是:
关键点是需要把html, body的height也设置成100%;
另外, 也可以用vh, vw
对于height, 只需height: 100vh;
vw, vh不是所有的浏览器都支持
谷歌调试中就有手机端界面,根据设备尺寸,多写点媒体查询
/* 关键字 */
background-size: cover
background-size: contain
或者
效果链接
具体的api属性
我也是有同样的问题,现在我一般就是用rem做的,但是计算根元素的font-size,还是会有些问题。
将图片做为背景,然后设置
background-size;对于容器的宽、高可以考虑用rem单位,然后动态计算html标签的font-size值;我一般都是这样做的
.container{
width:100%;
height:100%;
min-height:100%;
}
有的时候需要比较精确的计算,就用js计算出来高度,给赋值给height就行了