用REM單位進行移動端適配的最佳實現

大恆大發表於2020-11-16
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>aaa</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,shrink-to-fit=no">
		<style>
			:root{font-size: 20px;} 
		</style>
	</head>
	<body>
		TEST  TEST  TEST  TEST  TEST  TEST  TEST  
		<script>
			 let rootWidth = document.documentElement.clientWidth || document.body.clientWidth;
			 let rootDom = document.querySelector('html');
			 rootDom.style.fontSize = rootWidth / 10 + 'px';
		</script>
	</body>
</html>

相關文章