1. 程式人生 > >根據螢幕寬度,設定rem的值

根據螢幕寬度,設定rem的值

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
	<script type="text/javascript" rel="sheetstyle" src="jquery-1.9.1.min.js"></script>
	<style type="text/css">
		*{margin:0;padding:0;}
	</style>
	<script type="text/javascript">
		//$(window).width();
		function resize(){
			$('html').css('font-size',($(window).width())/10+'px');
		};
		window.onresize=resize;
		
		$(function(){resize();});
	</script>

</head>
<body>
	<div style="width:10rem;height:5rem;background:red;margin-left:auto;margin-right:auto"></div>
</body>
</html>