练习14_正方形.html 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. .box1{
  9. width: 100px;
  10. height: 100px;
  11. background-color: red;
  12. margin-bottom: 10px;
  13. }
  14. .box2{
  15. width: 100px;
  16. margin-bottom: 10px;
  17. }
  18. .box2::after{
  19. content: "";
  20. display: block;
  21. /* padding 百分比 相较于 父元素宽度 */
  22. padding-top: 100%;
  23. background-color: red;
  24. }
  25. .box3{
  26. width: 100px;
  27. height: 100px;
  28. position: relative;
  29. }
  30. .box3::after{
  31. content: "";
  32. display: block;
  33. position: absolute;
  34. top:0;
  35. left: 0;
  36. right: 0;
  37. bottom: 0;
  38. background-color: red;
  39. }
  40. </style>
  41. </head>
  42. <body>
  43. <div class="box1"></div>
  44. <div class="box2"></div>
  45. <div class="box3"></div>
  46. </body>
  47. </html>