CSS makes web pages adapt to different screen sizes (the most practical rem basic screen adaptation scheme)

Look at the code first, just copy and use, the following code can be copied and pasted (I will explain the code in the form of comments).

If you are satisfied, please give Mo Chengchen a Fabulous

Newton said: The reason why I see far is because I stand on the shoulders of giants, and we have fully borrowed elements, antd and other solutions to adapt.

It should be noted that using this scheme, you'd better use rem as the unit to set css, \color{#FF0000}{It should be noted that using this scheme, you'd better use rem as the unit to set css,} The need to inject meaning of is to make use of this a square case , you are most good to make use r E m as for the single- digit to set up set c S S , if they feel their calculation is too much trouble, you can use your compiler settings \ color { #FF0000}{If you think your calculations are troublesome, you can use your compiler settings}As if feel obtained from own count calculated ratio compared hemp trouble , may be to make use of your to compile the translation is provided opposite may specify the width in Blue Lake 120 as image \ color {# FF0000} {also be specified in the Blue lake The width is 120 as shown in the picture below}May also be in the blue lake the means specified width of is . 1 2 0 as the FIG sheet

Blue Lake Design

<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title></title>
	</head>
	<body>

	</body>
	<script type="text/javascript" charset="utf-8">
		//element 24栅栏布局是将页面等分为24份
		(function rem() {
    
    
			let fonts = document.documentElement.clientWidth / 120
			//我们获取到document.documentElement.clientWidth 即当前浏览器宽度 等分为120份
			// 一份的大小 在1440屏幕下 为12px, 在1920屏幕下 为16px
			if (fonts <= 12) {
    
    
				fonts = 12;
				document.documentElement.style.fontSize = fonts + "px"
				//当字体小于12 即1440 屏幕以下  我们让其为12
				document.documentElement.style.minWidth = '1440px'
				//同时设置屏幕的最小宽度为1440px
			} else if (fonts > 12 && fonts <= 16) {
    
    
				//如果在12--16之间  我们认为 此时屏幕宽度为 1440-1920之间  就可以使用
				document.documentElement.style.fontSize = document.documentElement.clientWidth / 120 + 'px';
			}
			window.onresize = rem;
			//window的窗口发生变化时  执行rem 函数 
			// 想必您已经知道了  我们在设置css 的单位时   将使用 rem
			// 比如  设计图  1920下 为100px   那么此时的单位应该为 6.25rem
		})()
	</script>
	 <script type="text/javascript">
		 //以下代码监听dom框架加载完成  做了一些常用处理
	  	document.addEventListener('DOMContentLoaded', function (event) {
    
    
	  	            //chrome浏览器
	  	            document.body.style.zoom = 'reset';
	  	            document.addEventListener('keydown', function (e) {
    
    
	  	                if ((e.ctrlKey === true || e.metaKey === true) &&
	  	                    (e.which === 61 || e.which === 107 || e.which === 173 || e.which === 109
	  	                        || e.which === 187 || e.which === 189)) {
    
    
	  	                    e.preventDefault();
	  	                }
	  	            }, false);
	  	            document.addEventListener('mousewhell DOMMouseScroll', function (e) {
    
    
	  	                if (e.ctrlKey === true || e.metaKey === true) {
    
    
	  	                    e.preventDefault();
	  	                }
	  	            }, false);
	  	        }, false);
	  </script>
</html>

Additional and useful information that may appear has been annotated

Guess you like

Origin blog.csdn.net/weixin_47821281/article/details/110949082