I. REM 1, meaning: When the px fixed width cannot accommodate different screen sizes, the layout needs to produce REM 2, REM and EM differences 2.1 rem:root, with the root node (HTML) as the reference size 2.2 em: Determine the size of 1em = 1font-size (parent) According to parent Font-size 3, change the HTML root element font-size as the screen width changes, thus controlling the REM value to achieve the corresponding effect (other HTML child elements width, etc. are REM)
function Autorem () { var html = document.documentelement; // DocumentElement returns the document root node HTML var htmlwidth = Html.getboundingclientrect (). width; // getboundingclientrect (). Width includes width + padding * 2 + border * 2 Html.style.fontSize = htmlwidth/16 + ' px '; // 16 is based on their own page settings, non-fixed use, in order to facilitate subsequent calculations (IPhone5 in the 320 screen, just divisible, a screen just 16rem) }// from this, assuming the iPhone5 test, then the html font-size = 320/60 = 20px 1rem = 20px
Second, use less to calculate the REM 1, less use method: 1.1 Installs the little operating environment (not the CSS pre-compiler, but the browser does not have its compilation environment, need to compile it into a CSS file, thereby indirectly using CSS) 1.1 .1 NPM install-g Less See the less Chinese network: http://lesscss.cn/1.2 to write the less files needed locally after installing less, such as Style.less 1.3 Open the Command window and switch to the folder where less files are located, compile the corresponding CSS file LESSC style.less style.css (lessc less file name CSS file name) 2, use less computing power, calculate REM
@r:10rem;. main{ 400/@r; 400px---->40rem}
Third, the use of border-sizing layout 1, the amount of size, width contains border and so on, and then normal settings border 2, Border-sizing:border-box; Let border in the width range (content contains width + padding + border) Next Chapter continued ...
02 Mobile-Side Layouts