5.媒体查询.html 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <!-- <link rel="stylesheet" href="./xxx" media="screen and (min-width:375px) and (max-width:414px)"> -->
  8. <style>
  9. #box{
  10. width: 200px;
  11. height: 200px;
  12. background: #00f;
  13. }
  14. @media screen and (min-width:375px) and (max-width:414px) {
  15. #box {
  16. background: #f00;
  17. }
  18. }
  19. @media screen and (min-width:500px) {
  20. #box {
  21. background: #ff0;
  22. }
  23. }
  24. </style>
  25. <!--
  26. //注意:中间必须有空格(and来连接多个条件的运行语句,only表示仅有条件,通过被忽略,not表示非/除了某个尺寸)
  27. 用 @media 开头 注意@符号
  28. mediaType 媒体类型
  29. 关键字 and not only
  30. media feature 媒体特性 必须有小括号包含
  31. 媒体类型
  32. all 所有设备
  33. screen 显示器 包括pc 手机端 移动端
  34. 样式引入
  35. <link rel="stylesheet" media="screen and (min-width:375px)" href="./style.css"/>
  36. <link rel="stylesheet" media="screen and (min-width:680px)" href="./style1.css"/>
  37. -->
  38. </head>
  39. <body>
  40. <div id="box"></div>
  41. </body>
  42. </html>