练习2_响应式布局.html 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. <style>
  8. body{
  9. margin: 0;
  10. }
  11. .container{
  12. max-width: 980px;
  13. margin: 0 auto;
  14. }
  15. img{
  16. display: none;
  17. width: 100%;
  18. }
  19. @media screen and (min-width:961px){
  20. .img1{
  21. display: block;
  22. }
  23. }
  24. @media screen and (max-width:960px) and (min-width:481px) {
  25. .img2{
  26. display: block;
  27. }
  28. }
  29. @media screen and (max-width:480px) {
  30. .img3{
  31. display: block;
  32. }
  33. .container .content{
  34. flex-wrap: wrap;
  35. }
  36. .container .content section{
  37. width: 100%;
  38. margin-right: 0;
  39. margin-bottom: 20px;
  40. }
  41. .container .content aside{
  42. width: 100%;
  43. }
  44. }
  45. header,nav,footer{
  46. background-color: #ccc;
  47. height: 50px;
  48. color: #fff;
  49. font-size: 30px;
  50. line-height: 50px;
  51. font-weight: bold;
  52. text-align: center;
  53. margin-bottom: 20px;
  54. }
  55. .content{
  56. display: flex;
  57. margin: 20px 0;
  58. }
  59. .content section{
  60. width: 55%;
  61. margin-right: 5%;
  62. height: 200px;
  63. background-color: red;
  64. }
  65. .content aside{
  66. width: 40%;
  67. height: 200px;
  68. background-color: blueviolet;
  69. }
  70. </style>
  71. </head>
  72. <body>
  73. <div class="container">
  74. <header>头部</header>
  75. <nav>导航</nav>
  76. <section>
  77. <img class="img1" src="./img/1.jpg" alt="img">
  78. <img class="img2" src="./img/2.jpg" alt="img">
  79. <img class="img3" src="./img/3.jpg" alt="img">
  80. </section>
  81. <div class="content">
  82. <section>IE8 及更早IE版本无法在这些元素中渲染CSS效果,以至于你不能使用 或者其他的HTML5 elements.IE8 及更早IE版本无法在这些元素中渲染CSS效果,以至于你不能使用 或者其他的HTML5 elements.</section>
  83. <aside>IE8 及更早IE版本无法在这些元素中渲染CSS效果,以至于你不能使用 或者其他的HTML5 elements.IE8 及更早IE版本无法在这些元素中渲染CSS效果,以至于你不能使用 或者其他的HTML5 elements.</aside>
  84. </div>
  85. <footer>尾部</footer>
  86. </div>
  87. </body>
  88. </html>