5.媒体查询.html 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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="./style/xxxx" media="screen and (min-width:375px) and (max-width:414px)">
  8. <style>
  9. #box {
  10. width: 2rem;
  11. height: 2rem;
  12. background: pink;
  13. }
  14. @media screen and (min-width:375px) and (max-width:414px) {
  15. #box {
  16. background: purple;
  17. }
  18. }
  19. @media screen and (min-width:768px){
  20. #box {
  21. background: red;
  22. }
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <div id="box"></div>
  28. <script src="./rem.js"></script>
  29. <!--
  30. 媒体查询
  31. @media 设备 关键字 条件 {代码块}
  32. 设备:
  33. screen:显示器 pc 手机
  34. all:所有设备
  35. 关键字:
  36. and not only
  37. 条件:
  38. min-xxx;max-xxx
  39. -->
  40. </body>
  41. </html>