完成一个 3 点的骰子

父元素

display: flex;
justify-content: space-between

第二个子元素

align-self:center;

第三个子元素

align-self:flex-end;

  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>flex 画骰子</title>
  8. <style>
  9. .box {
  10. width: 200px;
  11. height: 200px;
  12. border: 1px solid #ccc;
  13. border-radius: 10px;
  14. padding: 20px;
  15. display: flex;
  16. justify-content: space-between;
  17. }
  18. .item {
  19. width: 40px;
  20. height: 40px;
  21. background-color: #666;
  22. display: block;
  23. border-radius: 50%;
  24. }
  25. .item:nth-child(2) {
  26. align-self: center;
  27. }
  28. .item:nth-child(3) {
  29. align-self: flex-end;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <div class="box">
  35. <span class="item"></span>
  36. <span class="item"></span>
  37. <span class="item"></span>
  38. </div>
  39. </body>
  40. </html>