您现在的位置是: 网站首页>详情 文章详情

js 设置 rem

erhas2019-12-19 10:25:39javascript

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<title>rem设计</title>
	<script type="text/javascript">
		document.querySelector('html').style.fontSize=window.screen.width / 20 +'px';
		// 针对PC端的切换屏幕大小设置的
		window.onresize=function(){
			document.querySelector('html').style.fontSize=window.screen.width / 20 +'px';
		}
	</script>
	<style>
		.content{
			background-color: hotpink;
			width: 5rem;
			height: 5rem
		}
	</style>
</head>
<body>
	<div class="content">
		
	</div>
</body>
</html>