用于屏幕尺寸适应的媒体查询
在设计多种屏幕尺寸的网页布局时,媒体查询成为必不可少的工具。这些查询允许开发人员指定如何根据屏幕宽度调整布局。
针对特定屏幕尺寸应用媒体查询
要定位特定屏幕尺寸,请使用 media 属性最大宽度属性。例如,要将样式应用到宽度小于 800 像素的屏幕,请使用:
@media screen and (max-width: 800px) { /* Styles for screens less than 800px wide */ }
使用提供的代码示例
提供的代码示例使用以下媒体查询:
/* Smartphones (portrait and landscape) */ @media only screen and (min-device-width : 320px) and (max-device-width : 480px) { /* Styles for smartphones in portrait and landscape */ } /* Smartphones (landscape) */ @media only screen and (min-width : 321px) { /* Styles for smartphones in landscape */ } /* Smartphones (portrait) */ @media only screen and (max-width : 320px) { /* Styles for smartphones in portrait */ } /* iPads (portrait and landscape) */ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) { /* Styles for iPads in portrait and landscape */ } /* iPads (landscape) */ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) { /* Styles for iPads in landscape */ } /* iPads (portrait) */ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) { /* Styles for iPads in portrait */ } /* Desktops and laptops */ @media only screen and (min-width : 1224px) { /* Styles for desktops and laptops */ } /* Large screens */ @media only screen and (min-width : 1824px) { /* Styles for large screens */ } /* iPhone 4 - 5s */ @media only screen and (-webkit-min-device-pixel-ratio : 1.5), only screen and (min-device-pixel-ratio : 1.5) { /* Styles for iPhone 4 - 5s */ } /* iPhone 6 */ @media only screen and (max-device-width: 667px) only screen and (-webkit-device-pixel-ratio: 2) { /* Styles for iPhone 6 */ } /* iPhone 6+ */ @media only screen and (min-device-width : 414px) only screen and (-webkit-device-pixel-ratio: 3) { /* Styles for iPhone 6+ */ } /* Samsung Galaxy S7 Edge */ @media only screen and (-webkit-min-device-pixel-ratio: 3), and (min-resolution: 192dpi)and (max-width:640px) { /* Styles for Samsung Galaxy S7 Edge */ }
这些媒体查询涵盖各种屏幕尺寸,包括智能手机、平板电脑和更大的屏幕尺寸屏幕。
其他注意事项
考虑使用 em 值而不是像素,以便在不同屏幕尺寸下获得更大的灵活性。如需进一步指导,请参阅 Zell Weekley 的文章“媒体查询单元”。
以上是媒体查询如何帮助您设计适合不同屏幕尺寸的响应式网站?的详细内容。更多信息请关注PHP中文网其他相关文章!

在本周的综述中:Firefox获得了类似锁匠的力量,三星的Galaxy Store开始支持Progressive Web Apps,CSS Subgrid正在Firefox发货

在本周的综述中:Internet Explorer进入Edge,Google Search Console吹捧新的速度报告,Firefox提供了Facebook'

盖茨比(Gatsby)进行了出色的处理和处理图像。例如,它可以帮助您节省图像优化的时间,因为您不必手动


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

Dreamweaver CS6
视觉化网页开发工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。