Scenario: To adapt to screens of various sizes
Two ways I know of adaptive layout
1. Use media queries, formulated below There are several adaptation methods. For example, the first one indicates that the screen width is between 320px-360px, and the html font size is adapted to 13.65px
<style> @media only screen and (max-width: 360px) and (min-width: 320px){ html{ font-size:13.65px; } } @media only screen and (max-width: 375px) and (min-width: 360px){ html{ font-size:23.4375px; } } @media only screen and (max-width: 390px) and (min-width: 375px){ html{ font-size:23.4375px; } } @media only screen and (max-width: 414px) and (min-width: 390px){ html{ font-size:17.64px; } } @media only screen and (max-width: 640px) and (min-width: 414px){ html{ font-size:17.664px; } } @media screen and (min-width: 640px){ html{ font-size:27.31px; } } </style>
2. Responsive, get the width of the screen and calculate a certain For the proportion of size, use rem instead of px. When using it, such as font-size: 1rem, the size effect displayed on mobile phones with different screen sizes is different, and it is adaptive to the size ratio of the mobile phone screen
<script> (function(doc, win) { var docEl = doc.documentElement, //根元素html //判断窗口有没有orientationchange这个方法,有就赋值给一个变量,没有就返回resize方法。 resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', recalc = function() { var clientWidth = docEl.clientWidth; if(!clientWidth) return; //把document的fontSize大小设置成跟窗口成一定比例的大小,从而实现响应式效果。 if(clientWidth >= 640) { clientWidth = 640; } docEl.style.fontSize = 20 * (clientWidth / 320) + 'px'; console.log(clientWidth); console.log(docEl.style.fontSize); }; recalc(); if(!doc.addEventListener) return; win.addEventListener(resizeEvt, recalc, false); //addEventListener事件方法接受三个参数:第一个是事件名称比如点击事件onclick,第二个是要执行的函数,第三个是布尔值 doc.addEventListener('DOMContentLoaded', recalc, false) //绑定浏览器缩放与加载时间 })(document, window); </script>
<p id="p2" class="text" style="border: 0.04rem solid #ccc; height: 14rem;font-size: 0.5rem;">
Recommended tutorial: "HTML"
The above is the detailed content of HTML5 mobile adaptive layout. For more information, please follow other related articles on the PHP Chinese website!

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

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

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

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.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.