练习题1_弹性布局.html 2.8 KB

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