Mobile page rem layout_html/css_WEB-ITnose
The general size of mobile page design is 640. However, the size of mobile screen is indeed uncertain. In this way, how can we make a mobile page that adapts to all mobile phones?
There are two general solutions, rem layout and percentage layout. I have tried both solutions, so now I recommend using rem layout to create mobile pages;
Rem layout compatibility:
Mozilla Firefox 3.6, Apple Safari 5 , Google Chrome, IE9 and Opera11, ie6-ie8, it’s better not to use rem
However, with the general browsers on mobile phones nowadays, you can generally just ignore the IE kernel browser.
REM calculation formula
Example: html set font-size:16px 1rem = 16px
Then 640px = 640/16 =40rem
Personal suggestion Set to 100px for easy calculation
First, define a 100px
html{ font-size:100px;}/*Set the basic rem*/
Then, the core code is this js operation, which controls the basic rem value according to the size of the page;
<p class="sycode"> <p class="sycode"> new function (){ var _self = this; _self.width = 640; // 设置默认最大宽度 _self.fontSize = 100; // 默认字体大小 _self.widthProportion = function(){ var p = (document.body&&document.body.clientWidth||document.getElementsByTagName("html")[0].offsetWidth)/_self.width;return p>1?1:p<0.5?0.5:p;}; _self.changePage = function(){ document.getElementsByTagName("html")[0].setAttribute("style","font-size:"+_self.widthProportion()*_self.fontSize+"px !important"); } _self.changePage(); window.addEventListener('resize', function(){_self.changePage();}, false);}; </p> </p>
demo
< html >
< head >
< meta name ="viewport" content ="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" >
< meta charset ="utf-8" >
< title >rem基础布局 title >
< script type ="text/javascript" >
new function (){
var _self = this;
_self.width = 640; // 设置默认最大宽度
_self.fontSize = 100; // 默认字体大小
_self.widthProportion = function(){ var p = (document.body&&document.body.clientWidth||document.getElementsByTagName("html")[0].offsetWidth)/_self.width;return p>1?1:p<0.5?0.5:p;};
_self.changePage = function(){
document.getElementsByTagName("html")[0].setAttribute("style","font-size:" _self.widthProportion()*_self.fontSize "px !important");
}
_self.changePage();
window.addEventListener('resize', function(){_self.changePage();}, false);
};
script >
< style type ="text/css" >
/* === base style=== */
*{ margin: 0px; padding: 0px;}
ul{ list-style: none;}
.wrap{ min-width: 320px; max-width: 640px; width: 100%; margin: 0px auto; ; background: #2a6ace; font-family: '微软雅黑', 'helvetica neue',tahoma,'hiragino sans gb',stheiti,'wenquanyi micro hei',5FAE8F6F96C59ED1,5B8B4F53,sans-serif; font-size: 12px;} /* 适用于手机端:字体大小用em,1em=16px;为默认字体大小;最大宽度640 */
.pro{ width: 6.2rem; margin: 0px auto; padding-top: 20px; overflow: hidden;}
.clearfix:after { content: ""; height: 0; display: block; clear: both;}
.clearfix { zoom: 1;}
.pro ul{ width: 6.4rem;}
.pro li{ width: 3rem; height: 3.6rem; float: left; margin: 0 0.2rem 0.2rem 0;}
.pro li .box{ width: 3rem; height: 3rem; background: #ccc;}
.pro li p{ font-size: 0.24rem; line-height: 0.6rem; text-align: center;}
style >
head >
< body >
< div class ="wrap" >
< div class ="pro" >
< ul class ="clearfix" >
< li > < div class ="box" > div > < p >区块文案 p > li >
< li > < div class ="box" > div > < p >区块文案 p > li >
< li > < div class ="box" > div > < p >区块文案 p > li >
< li > < div class ="box" > div > < p >区块文案 p > li >
< li > < div class ="box" > div > < p >区块文案 p > li >
ul >
div >
div >
body >
html >

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...
