5_媒体查询.html 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. <!-- 响应式布局 根据屏幕尺寸 来加载不同的css文件 -->
  8. <link rel="stylesheet" media="screen and (max-width:1000px) and (min-width:600px)" href="./css/a.css">
  9. <link rel="stylesheet" media="screen and (min-width:1200px)" href="./css/b.css">
  10. <style>
  11. .box{
  12. width: 1000px;
  13. height: 600px;
  14. background-color: red;
  15. }
  16. /* @media 媒体查询 根据屏幕类型和尺寸 来控制样式 */
  17. @media screen and (max-width:1000px) and (min-width:600px){
  18. .box{
  19. background-color: blue;
  20. }
  21. }
  22. @media screen and (min-width:1200px){
  23. .box{
  24. background-color: green;
  25. }
  26. }
  27. /* @media 媒体查询 orientation 根据屏幕方向 来控制样式 landscape 横屏 */
  28. @media screen and (orientation:landscape){
  29. .box{
  30. background-color: pink;
  31. }
  32. }
  33. /* 竖屏 */
  34. @media screen and (orientation:portrait){
  35. .box{
  36. background-color: yellow;
  37. }
  38. }
  39. </style>
  40. </head>
  41. <body>
  42. <div class="box">hello world</div>
  43. </body>
  44. </html>