This time I will show you how to use rem+scss for adaptation on the mobile phone. What are theprecautions for adapting rem+scss on the mobile phone? The following is a practical case, let’s take a look.
rem introduction rem (font size of the root element) refers to the unit of font size relative to the root element (i.e.html element).
Assume that the font size of the root element is 10px, then the size of 5rem is 5*10=50px, for examplehtml{ font-size: 10px; } p{ width: 2rem; /* 2*10 = 20px;*/ margin: 1rem; }
html header)
// 默认16是html默认字号 // 默认750是设计稿默认宽度 // $n是量取设计稿的距离 @charset "UTF-8"; @function rem($n) { @return $n / (750 / 16)+rem; }
@function getTop($n) { @return ($n - 1206 / 2) / (750 / 16)+rem; } @function getLeft($n) { @return ($n - 750 / 2) / (750 / 16)+rem; } @function getRight($n) { @return (($n - 750) / 2) / (750 / 16)+rem; } @mixin center($left, $top) { //左右居中 上变 position: absolute; left: 50%; top: rem($top); margin: 0 0 0 getLeft($left); } @mixin centerlt($left, $top) { //上下,左右居中 position: absolute; left: 50%; top: 50%; margin: getTop($top) 0 0 getLeft($left); } @mixin centerrt($right, $top) { //上下,左右居中 position: absolute; right: 50%; top: 50%; margin: getTop($top) getRight($right) 0 0; } @mixin middlert($right, $top) { //上下居中 右变 position: absolute; right: rem($right); top: 50%; margin: getTop($top) 0 0 0; } @mixin centerb($left, $bottom) { //左右居中 下变 position: absolute; left: 50%; bottom: rem($bottom); margin: 0 0 0 getLeft($left); } @mixin leftTop($left, $top) { //左变 上变 position: absolute; left: rem($left); top: rem($top); } @mixin rightTop($right, $top) { //右变 上变 position: absolute; right: rem($right); top: rem($top); } @mixin leftBottom($left, $bottom) { //右变 上变 position: absolute; left: rem($left); bottom: rem($bottom); }
page1-img1{ width: rem(473); height: rem(173); @include centerlt(139, 767); }
html5 How to create a circle animation effect of pictures
How to use H5’s WebGL in the same The interface makes json and echarts charts
How to use the new semantic tag features of H5
The above is the detailed content of How to use rem+scss for adaptation on the mobile phone. For more information, please follow other related articles on the PHP Chinese website!