vw:视窗宽度的百分比(1vw 代表视窗的宽度为 1%)
vh:视窗高度的百分比
vmin:当前 vw 和 vh 中较小的一个值
vmax:当前 vw 和 vh 中较大的一个值
(1)桌面 pc
chrome:自 26 版起就完美支持(2013年2月)
firefox:自 19 版起就完美支持(2013年1月)
safari:自 6.1 版起就完美支持(2013年10月)
opera:自 15 版起就完美支持(2013年7月)
ie:自 ie10 起(包括 edge)到现在还只是部分支持(不支持 vmax,同时 vm 代替 vmin)
(2)移动设备
android:自 4.4 版起就完美支持(2013年12月)
ios:自 ios8 版起就完美支持(2014年9月)
从目前来看,新的浏览器基本都支持,除非项目有特别的要求,完全可以放心使用。
<!doctype html>
<html lang="en">
<head>
<title></title>
<meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1" />
<meta name="viewport" content="width=device-width">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<style>
html,body {
margin: 0;
padding: 0;
width:100%;
height:100%;
overflow: hidden;
background: #000;
}
.playerbox {
border: 1px solid #f7ff00;
width: 90vw; /* 宽度 页面宽度的90% */
height: 60vh; /* 高度 页面高度的60% */
background: #75dca2;
/* 容器自动水平居中 */
margin: 0px auto;
/* 实现垂直居中 距顶部高度 也可以写成 calc((100vh - 60vh)/2) */
margin-top: 20vh;
text-align: center; /* 文字水平居中 */
line-height: 60vh; /* 文字垂直居中 */
color: #fff;
}
</style>
</head>
<body>
<div id="playerbox" class="playerbox">我上下左右居中</div>
</body>
</html>
如对本文有疑问, 点击进行留言回复!!
CSS中的两个特殊值用于控制层叠的inherit和initial的方法
CSS3 input框的实现代码类似Google登录的动画效果
CSS 容器背景 10 种颜色渐变Demo(linear-gradient())
详解CSS文件中的4种引入方式:行内,内联式,外部式,导入式
网友评论