用於螢幕尺寸適應的媒體查詢
在設計多種螢幕尺寸的網頁版面時,媒體查詢成為不可或缺的工具。這些查詢允許開發人員指定如何根據螢幕寬度調整佈局。
針對特定螢幕尺寸套用媒體查詢
要定位特定螢幕尺寸,請使用 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搜索控制台吹捧新的速度報告,而Firefox給出了Facebook' s Notification

蓋茨比(Gatsby)進行了出色的處理和處理圖像。例如,它可以幫助您節省圖像優化的時間,因為您不必手動


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

Dreamweaver CS6
視覺化網頁開發工具

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。