当前位置:  首页>> 技术小册>> Web响应式布局入门到实战

多个style段定义媒体查询:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. .div0{
  10. width:100%;
  11. height:500px;
  12. border:1px solid #ccc;
  13. }
  14. /* 子div浮动一行显示 */
  15. .div0 div{
  16. float:left;
  17. height:200px;
  18. }
  19. .div0 div:nth-child(1){
  20. background-color: red;
  21. }
  22. .div0 div:nth-child(2){
  23. background-color: green;
  24. }
  25. .div0 div:nth-child(3){
  26. background-color: blue;
  27. }
  28. </style>
  29. <style media="(min-width:300px) and (max-width:399px)">
  30. .div0 div{
  31. width: 50%;
  32. }
  33. </style>
  34. <style media="(min-width:400px)">
  35. .div0 div{
  36. width: 33.3%;
  37. }
  38. </style>
  39. </head>
  40. <body>
  41. <div class="div0">
  42. <div></div>
  43. <div></div>
  44. <div></div>
  45. </div>
  46. </body>
  47. </html>

该分类下的相关小册推荐: