How to use rem+scss for adaptation on the mobile phone
This time I will show you how to use rem+scss for adaptation on the mobile phone. What are the precautions for adapting rem+scss on the mobile phone? The following is a practical case, let’s take a look.
rem introductionrem (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)
<script type="text/javascript"> var bodyElement = document.documentElement || document.body, RC = { w: 750, h: 1206 }, //默认设计稿宽高 GC = { w: document.documentElement.clientWidth || window.innerWidth || screen.width, h: document.documentElement.clientHeight || window.innerHeight || screen.height }; function setFontSize(){ var rightSize = parseFloat((RC.w / RC.h).toFixed(1)), currentSize = parseFloat((GC.w / GC.h).toFixed(1)), lastHTMLSize = 16, // 默认16是因为html默认字号是16px html = document.getElementsByTagName("html")[0]; if(rightSize > currentSize){ // 长屏 lastHTMLSize = 16; }else if(rightSize < currentSize){ //宽屏 lastHTMLSize = (RC.h / GC.h * GC.w) / RC.w * 16; } html.style.fontSize = GC.w / lastHTMLSize + 'px'; } setFontSize(); </script>
// 默认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!

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

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

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.

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

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-
