搜索文档
首页
HTML/CSS
JavaScript
服务端开发
Java教程
移动端
数据库
当前位置:
首页
HTML/CSS
CSS3教程
CSS3基础教程
源代码
清空
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>CSS媒体查询示例 -基础教程 div.cn</title> <style> /* Smartphones (portrait and landscape) ---------- */ @media screen and (min-width: 320px) and (max-width: 480px){ body{ background: #7ce7e1; } } /* Smartphones (portrait) ---------- */ @media screen and (max-width: 320px){ body{ background: #ffd280; } } /* Smartphones (landscape) ---------- */ @media screen and (min-width: 321px){ body{ background: #9ddfbb; } } /* tablets, iPads (portrait and landscape) ---------- */ @media screen and (min-width: 768px) and (max-width: 1024px){ body{ background: #ffb497; } } /* tablets, iPads (portrait) ---------- */ @media screen and (min-width: 768px){ body{ background: #f0e68c; } } /* tablets, iPads (landscape) ---------- */ @media screen and (min-width: 1024px){ body{ background: #d6b3f4; } } /* Desktops and laptops ---------- */ @media screen and (min-width: 1224px){ body{ background: #d8ff9d; } } /* Large screens ---------- */ @media screen and (min-width: 1824px){ body{ background: #ffc0cb; } } </style> </head> <body> <h1> CSS媒体查询</h1> <p>在不同的媒体或设备中,输出区域的背景是不同的。</p> <p> <strong>替代</strong>:您还可以通过在新窗口中打开输出并将其大小调整为其他大小来查看此媒体查询的效果。</p> </body> </html>
运行结果