Table of Contents
回复内容:
Home Web Front-end H5 Tutorial 如何使用 HTML5 技术适配不同分辨率的设备?

如何使用 HTML5 技术适配不同分辨率的设备?

Jun 07, 2016 am 08:45 AM

回复内容:

简单说,CSS media query。具体实现就比较复杂了,比如media query各浏览器支持程度不一。此外在技术实现之前,首先你在设计层面要有这个意识。有时候,适配不仅仅是分辨率(resolution)问题,还有DPI问题。另外还有操作差异,比如触摸(手持设备)还是鼠标(desktop)还是遥控器(Web TV)。在许多场合下,还是会考虑做独立的版本,而不是在一个版本里进行适配。 实际上根本没有方法解决, 设备的密度不同js无法解决,最好的方法就是就麻烦的方法,一个按钮多做几种尺寸,多写几种组件代码 自适应不是HTML5的功能,想想在电脑上网页是怎么自适应宽度的,举个例子用width=100%就可以在不同分辨率的显示器上显示同样的效果了,HTML自推出就涵盖了这种功能,不论是显示器还是手机屏幕,其实大同小异了 自适应宽度 适配不同分辨率的设备应该是用到CSS的Media Queries(媒体查询)技术,只要设备支持媒体查询功能,应该都会识别,CSS2.1定义了10种设备类型,共有13种设备特性,详情见yiiyaa.net/1451 个人经验,分两步,完美解决:
1,服务器端判断UA
2,移动设备用viewport

题主希望能够适配不同设备,肯定不是静态页面吧,毕竟用到“适配”这个词,肯定是希望不同内容能够分别占据适当的体积、能够根据页面宽度布置不同的块吧?
那么在这样的前提下,我们想要的效果显而易见,对于电脑,左右可以有边栏、可以有更细小的按钮、更多的特效,而在手机上访问的时候,要简洁、快速、省流量
所以,首先根据UA判断用户用什么设备访问,是电脑就输出适用电脑的复杂的内容+CSS,是移动设备就输出适用于移动设备的简洁的内容+CSS。
用UA还有一个好处,就是能够配合Cookie很方便地让用户自己选择适配。比如用户的UA没有识别出来,用户其实是手机+小众的浏览器,但是你提供了电脑版,用其他的方式很难想象如何去适配,但是配合Cookie,只要用户选一次版式,以后都不会出问题。甚至,我本人有时候喜欢用手机上电脑版(因为电脑版往往功能多),我们应该给用户这个自由(如果不打算给的话,就更需要检查UA了)
然后,很意外的是没有看到有人说viewport,难道大家都不做移动开发或者做的时候不去适配多平台多设备?viewport对开发者非常方便,声明以后,你只要按照屏幕宽度320px(小屏)或者360px(大屏,也可以把小屏的直接居中,这里顺便吐槽一下MX3的4xx px)去开发,不管设备物理分辨率是多少,都会按比例矢量缩放到满屏(横向,纵向不谈了)。比如viewport声明320px宽以后,iPhone 5s上满屏,800x480的安卓满屏,720的安卓满屏,1080的安卓只在两边有两个细白条,一居中就行了
是不是感觉仿佛特简单?
真的很简单,快点百度学学viewport,然后请后端同学吃个饭让他帮你搞定UA,适配多设备多平台从此不是梦 css2/css3里面有个@media ,用法如 @media all and (device-height:800px){ … } ,应该能解决你的问题吧。 通过rem 和 媒体查询结合使用
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1660
14
PHP Tutorial
1260
29
C# Tutorial
1233
24
What exactly does H5 page production mean? What exactly does H5 page production mean? Apr 06, 2025 am 07:18 AM

H5 page production refers to the creation of cross-platform compatible web pages using technologies such as HTML5, CSS3 and JavaScript. Its core lies in the browser's parsing code, rendering structure, style and interactive functions. Common technologies include animation effects, responsive design, and data interaction. To avoid errors, developers should be debugged; performance optimization and best practices include image format optimization, request reduction and code specifications, etc. to improve loading speed and code quality.

How to run the h5 project How to run the h5 project Apr 06, 2025 pm 12:21 PM

Running the H5 project requires the following steps: installing necessary tools such as web server, Node.js, development tools, etc. Build a development environment, create project folders, initialize projects, and write code. Start the development server and run the command using the command line. Preview the project in your browser and enter the development server URL. Publish projects, optimize code, deploy projects, and set up web server configuration.

How to make h5 click icon How to make h5 click icon Apr 06, 2025 pm 12:15 PM

The steps to create an H5 click icon include: preparing a square source image in the image editing software. Add interactivity in the H5 editor and set the click event. Create a hotspot that covers the entire icon. Set the action of click events, such as jumping to the page or triggering animation. Export H5 documents as HTML, CSS, and JavaScript files. Deploy the exported files to a website or other platform.

How to make pop-up windows with h5 How to make pop-up windows with h5 Apr 06, 2025 pm 12:12 PM

H5 pop-up window creation steps: 1. Determine the triggering method (click, time, exit, scroll); 2. Design content (title, text, action button); 3. Set style (size, color, font, background); 4. Implement code (HTML, CSS, JavaScript); 5. Test and deployment.

Is h5 same as HTML5? Is h5 same as HTML5? Apr 08, 2025 am 12:16 AM

"h5" and "HTML5" are the same in most cases, but they may have different meanings in certain specific scenarios. 1. "HTML5" is a W3C-defined standard that contains new tags and APIs. 2. "h5" is usually the abbreviation of HTML5, but in mobile development, it may refer to a framework based on HTML5. Understanding these differences helps to use these terms accurately in your project.

H5 Code: Accessibility and Semantic HTML H5 Code: Accessibility and Semantic HTML Apr 09, 2025 am 12:05 AM

H5 improves web page accessibility and SEO effects through semantic elements and ARIA attributes. 1. Use, etc. to organize the content structure and improve SEO. 2. ARIA attributes such as aria-label enhance accessibility, and assistive technology users can use web pages smoothly.

What Does H5 Refer To? Exploring the Context What Does H5 Refer To? Exploring the Context Apr 12, 2025 am 12:03 AM

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

How to solve the h5 compatibility problem How to solve the h5 compatibility problem Apr 06, 2025 pm 12:36 PM

Solutions to H5 compatibility issues include: using responsive design that allows web pages to adjust layouts according to screen size. Use cross-browser testing tools to test compatibility before release. Use Polyfill to provide support for new APIs for older browsers. Follow web standards and use effective code and best practices. Use CSS preprocessors to simplify CSS code and improve readability. Optimize images, reduce web page size and speed up loading. Enable HTTPS to ensure the security of the website.

See all articles