• 前端html原生页面兼容多端H5和移动端适配方案



    px 与 rem 互转在线工具

    图片

    是一个注册页面
    请添加图片描述

    代码

    自己查看效果

    注意: 单位全部用rem这样才能保证兼容性适配多端,px转rem转换公式
    1px = 1/37.5rem
    所以想要20px应该对应20/37.5 = 0.53rem

    DOCTYPE html>
    <html lang="en">
    	<head>
    		<meta charset="UTF-8">
    		<meta http-equiv="X-UA-Compatible" content="IE=edge">
    		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
    		<title>注册五福亿家title>
    		<style>
    			* {
    				margin: 0;
    				padding: 0
    			}
    
    			/* 但这样我们会发现在写布局的时候会非常复杂,也就是你需要自己手动去计算一下对应的rem值,
    比如上面的font-size设计稿上是20px,那我们就要计算一下20px对应的rem是多少,
    按我们上面的规则,1px = 1/37.5rem,所以20px应该对应20/37.5 = 0.53rem */
    
    			.register {
    				width: 10rem;
    				height: 4rem;
    				/* background-color: antiquewhite; */
    				/* 18px 以18px字体为基准*/
    				font-size: 0.48rem;
    			}
    
    			.register_box {
    				padding: 0.4rem 0.98rem;
    				box-sizing: border-box;
    			}
    
    			.register_nav {
    				padding: 2.4rem 0;
    				padding-bottom: 1.46rem;
    			}
    
    			.title {
    				font-size: 0.69rem;
    				font-weight: 600;
    				margin-bottom: 0.42rem;
    			}
    
    			.register_form {
    				display: flex;
    				flex-direction: column;
    			}
    
    			.form_list {
    				display: flex;
    				align-items: center;
    			}
    
    			.form_list_tit {
    				font-size: 0.45rem;
    				/* 	position: relative;
    				bottom: 1px; */
    				width: 3rem;
    			}
    
    			.form_list_ipt {
    				width: 4.96rem;
    				height: 1.2rem;
    				border-bottom: 0.02rem solid #f4f4f4;
    				/* border: 0.02rem solid red; */
    				display: flex;
    				justify-content: center;
    			}
    
    			.form_list_ipt input {
    				outline: none;
    				background: transparent;
    				border: none;
    				outline: medium;
    				width: 100%;
    				/* font-size: 0.45rem; */
    			}
    
    			// 当输入框获取焦点时
    			.form_list_ipt input:focus {
    				outline: none;
    				background-color: transparent;
    			}
    
    			// 选择输入文本时,默认蓝色,改为透明
    			::selection {
    				background: transparent;
    			}
    
    			::-moz-selection {
    				background: rgb(241, 241, 241);
    			}
    
    
    			/* 阅读 */
    			.read {
    				padding-top: 0.4rem;
    				display: flex;
    				flex-direction: row;
    				align-items: center;
    			}
    
    			.read_size {
    				font-size: 0.1rem;
    				color: f4f4f4;
    			}
    
    			.read_size_grn {
    				font-size: 0.1rem;
    				color: rgb(26, 173, 88);
    			}
    
    			.read_size_radio {
    				margin-right: 0.1rem;
    			}
    
    			.read_size_rgt {
    				margin-right: 0.1rem;
    			}
    
    			#registerBtn {
    				width: 100%;
    				height: 1.2rem;
    				line-height: 1.2rem;
    				font-size: 0.45rem;
    				border-radius: 0.58rem;
    				color: #ffffff;
    				background-color: #19ad57;
    				margin: 0.4rem 0;
    				text-align: center;
    			}
    		style>
    		<script>
    			function setRootRem() {
    				const root = document.documentElement;
    				/** 以iPhone6为例:布局视口为375px,我们把它分成10份,则1rem = 37.5px,
    				 * 这时UI给定一个元素的宽为375px(设备独立像素),
    				 * 我们只需要将它设置为375 / 37.5 = 10rem。
    				 */
    				const scale = root.clientWidth / 10
    				root.style.fontSize = scale + 'px'
    			}
    			setRootRem()
    			window.addEventListener('resize', setRootRem)
    		script>
    	head>
    	<body>
    		<div class="register">
    			<div class="register_box">
    				<div class="register_nav">
    					<div class="title">
    						注册五福亿家
    					div>
    				div>
    				<div class="register_form">
    					<div class="form_list">
    						<div class="form_list_tit">手机号div>
    						<div class="form_list_ipt">
    							<input type="number" id="mobile" placeholder="请填写手机号">
    						div>
    					div>
    
    					<div class="form_list">
    						<div class="form_list_tit">昵称div>
    						<div class="form_list_ipt">
    							<input type="text" id="nick_name" placeholder="请填写昵称">
    						div>
    					div>
    
    					<div class="form_list">
    						<div class="form_list_tit">推荐人div>
    						<div class="form_list_ipt">
    							<input type="number" id="referee_id" placeholder="请填写推荐人">
    							
    						div>
    					div>
    
    					<div class="form_list">
    						<div class="form_list_tit">登录密码div>
    						<div class="form_list_ipt">
    							<input type="password" id="password" placeholder="请填写登录密码">
    						div>
    					div>
    
    					<div class="form_list">
    						<div class="form_list_tit">确认登录密码div>
    						<div class="form_list_ipt">
    							<input type="password" id="repassword" placeholder="请填写确认登录密码">
    						div>
    					div>
    
    					<div class="form_list">
    						<div class="form_list_tit">支付密码div>
    						<div class="form_list_ipt">
    							<input type="password" id="pay_password" placeholder="请填写支付密码">
    						div>
    					div>
    
    					<div class="form_list">
    						<div class="form_list_tit">确认支付密码div>
    						<div class="form_list_ipt">
    							<input type="password" id="repay_password" placeholder="请填写确认支付密码">
    						div>
    					div>
    				div>
    
    				<div class="read">
    					<div class="read_size read_size_radio">
    						<input type="radio" checked>
    					div>
    					<div class="read_size read_size_rgt">
    						我已阅读并接受
    					div>
    					<div class="read_size_grn">
    						《用户协议》
    					div>
    					<div class="read_size">div>
    					<div class="read_size_grn">
    						《隐私政策》
    					div>
    				div>
    
    
    				<div id="registerBtn">
    					注册
    				div>
    			div>
    		div>
    	body>
    	<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.js">script>
    	<script>
    		var mobile = document.getElementById('mobile');
    		var nick_name = document.getElementById('nick_name');
    		var referee_id = document.getElementById('referee_id');
    		var password = document.getElementById('password');
    		var repassword = document.getElementById('repassword');
    		var pay_password = document.getElementById('pay_password');
    		var repay_password = document.getElementById('repay_password');
    
    		var registerBtn = document.getElementById('registerBtn');
    		
    		registerBtn.onclick = function() {
    
    				var mobiles = mobile.value;
    				var nickName = nick_name.value;
    				var refereeId = referee_id.value;
    				var passwords = password.value;
    				var repasswords = repassword.value;
    				var payPassword = pay_password.value;
    				var repayPassword = repay_password.value;
    
    
    				// 验证  
    				if (!mobiles || !nickName || !refereeId || !passwords || !repasswords || !payPassword || !repayPassword) {
    					// alert('账号或密码不能为空')
    					alert('请输入,不能为空')
    					return
    				}
    				
    				// 提交数据  
    				$.ajax({
    					type:"POST",
    					url:'https://wfyj.yunjingwl.com/index.php/api/user.useropen/register',
    					data: {
    						app_id: 10001,
    						mobile: mobiles,
    						nick_name: nickName,
    						referee_id: refereeId,
    						password: passwords,
    						repassword: repasswords,
    						pay_password: payPassword,
    						repay_password: repayPassword,
    						// type: 'add',
    					},
    					// https://www.cnblogs.com/hanguidong/p/9442927.html // 用JSON来传数据,靠JSONP来跨域
    					// dataType: 'JSONP',
    					dataType: 'JSON',
    					// Headers:{
    					// 	"Access-Control-Allow-Origin":'*'
    					// },
    					
    					crossDomain: true,
    					success: function(json) {
    						alert(json.msg)
    					},
    					error: function(code) {
    						alert(code)
    					}
    				})
    			}
    	script>
    html>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292

    参考

    大佬
    大佬

    最后

    感觉文章好的话记得点个心心和关注和收藏,有错的地方麻烦指正一下,如果需要转载,请标明出处,多谢!!!

  • 相关阅读:
    java.lang.UnsatisfiedLinkError: dlopen failed: library “libsqlite.so“ not found
    带头双向循环链表的实现(C语言)
    如何将用户导入自己的私域流量?“分享购“案例分享
    c语言---19函数的调用
    11、C++进阶编程STL
    接口自动化测试yaml+requests+allure技术,你学会了吗?
    机器人中的数值优化|【三】无约束优化,拟牛顿法,共轭梯度法理论与推导
    Redis持久化AOF/RDB
    二、vue2脚手架-组件化开发
    Docker基本管理
  • 原文地址:https://blog.csdn.net/m0_49714202/article/details/132882292