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); }Call the above function (width and height distances can be measured in ps to measure the actual distance. The default design draft width is 750) :
page1-img1{ width: rem(473); height: rem(173); @include centerlt(139, 767); }I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website! Related reading:
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!

The H5 tag in HTML is a fifth-level title that is used to tag smaller titles or sub-titles. 1) The H5 tag helps refine content hierarchy and improve readability and SEO. 2) Combined with CSS, you can customize the style to enhance the visual effect. 3) Use H5 tags reasonably to avoid abuse and ensure the logical content structure.

The methods of building a website in HTML5 include: 1. Use semantic tags to define the web page structure, such as, , etc.; 2. Embed multimedia content, use and tags; 3. Apply advanced functions such as form verification and local storage. Through these steps, you can create a modern web page with clear structure and rich features.

A reasonable H5 code structure allows the page to stand out among a lot of content. 1) Use semantic labels such as, etc. to organize content to make the structure clear. 2) Control the rendering effect of pages on different devices through CSS layout such as Flexbox or Grid. 3) Implement responsive design to ensure that the page adapts to different screen sizes.

The main differences between HTML5 (H5) and older versions of HTML include: 1) H5 introduces semantic tags, 2) supports multimedia content, and 3) provides offline storage functions. H5 enhances the functionality and expressiveness of web pages through new tags and APIs, such as and tags, improving user experience and SEO effects, but need to pay attention to compatibility issues.

The difference between H5 and HTML5 is: 1) HTML5 is a web page standard that defines structure and content; 2) H5 is a mobile web application based on HTML5, suitable for rapid development and marketing.

The core features of HTML5 include semantic tags, multimedia support, form enhancement, offline storage and local storage. 1. Semantic tags such as, improve code readability and SEO effect. 2. Multimedia support simplifies the process of embedding media content through and tags. 3. Form Enhancement introduces new input types and verification properties, simplifying form development. 4. Offline storage and local storage improve web page performance and user experience through ApplicationCache and localStorage.

HTML5isamajorrevisionoftheHTMLstandardthatrevolutionizeswebdevelopmentbyintroducingnewsemanticelementsandcapabilities.1)ItenhancescodereadabilityandSEOwithelementslike,,,and.2)HTML5enablesricher,interactiveexperienceswithoutplugins,allowingdirectembe

Advanced tips for H5 include: 1. Use complex graphics to draw, 2. Use WebWorkers to improve performance, 3. Enhance user experience through WebStorage, 4. Implement responsive design, 5. Use WebRTC to achieve real-time communication, 6. Perform performance optimization and best practices. These tips help developers build more dynamic, interactive and efficient web applications.


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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
