• CSS 用 flex 布局绘制骰子


    1. html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8">
    5. <title>title>
    6. <style>
    7. .box {
    8. height: 100px;
    9. width: 100px;
    10. border: 2px solid grey;
    11. border-radius: 10px;
    12. display: flex;
    13. justify-content: center; // 水平居中
    14. /* align-items: center; */
    15. }
    16. .point {
    17. width: 20px;
    18. height: 20px;
    19. border-radius: 50%;
    20. background: black;
    21. /* align-self 写在子元素上,覆盖父元素指定的交叉轴对齐方式 */
    22. align-self: center;
    23. }
    24. style>
    25. head>
    26. <body>
    27. <div class="box">
    28. <div class="point">div>
    29. div>
    30. body>
    31. html>

     

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8">
    5. <title>title>
    6. <style>
    7. .box {
    8. height: 100px;
    9. width: 100px;
    10. border: 2px solid grey;
    11. border-radius: 10px;
    12. display: flex;
    13. /* 主轴改为纵向 */
    14. flex-direction: column;
    15. /* 等分 */
    16. justify-content: space-evenly;
    17. /* 垂直居中 */
    18. align-items: center;
    19. }
    20. .point {
    21. width: 20px;
    22. height: 20px;
    23. border-radius: 50%;
    24. background: black;
    25. }
    26. style>
    27. head>
    28. <body>
    29. <div class="box">
    30. <div class="point">div>
    31. <div class="point">div>
    32. div>
    33. body>
    34. html>

     

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8">
    5. <title>title>
    6. <style>
    7. .box {
    8. height: 100px;
    9. width: 100px;
    10. border: 2px solid grey;
    11. border-radius: 10px;
    12. display: flex;
    13. padding: 10px;
    14. /* 主轴改为纵向 */
    15. flex-direction: column;
    16. /* 子元素间距相等*/
    17. justify-content: space-between;
    18. }
    19. .point {
    20. width: 25px;
    21. height: 25px;
    22. border-radius: 50%;
    23. background: black;
    24. }
    25. .point:nth-child(2) {
    26. /* 居中对齐 */
    27. align-self: center;
    28. }
    29. .point:nth-child(3) {
    30. /* 终点对齐 */
    31. align-self: flex-end;
    32. }
    33. style>
    34. head>
    35. <body>
    36. <div class="box">
    37. <div class="point">div>
    38. <div class="point">div>
    39. <div class="point">div>
    40. div>
    41. body>
    42. html>

    1. 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>title>
    7. <style>
    8. .box {
    9. margin: 20px;
    10. height: 100px;
    11. width: 100px;
    12. border: 2px solid grey;
    13. border-radius: 10px;
    14. padding: 10px;
    15. box-sizing: border-box;
    16. display: flex;
    17. /* 纵向 */
    18. flex-wrap: wrap;
    19. /* 相对均匀对齐 */
    20. align-content: space-between;
    21. }
    22. .row {
    23. /* 空间大小 */
    24. flex-basis: 100%;
    25. display: flex;
    26. justify-content: space-between
    27. }
    28. .point {
    29. border-radius: 50%;
    30. height: 25px;
    31. width: 25px;
    32. background: black;
    33. }
    34. style>
    35. head>
    36. <body>
    37. <div class="box">
    38. <div class="row">
    39. <div class="point">div>
    40. <div class="point">div>
    41. div>
    42. <div class="row">
    43. <div class="point">div>
    44. <div class="point">div>
    45. div>
    46. div>
    47. body>
    48. html>

     

    1. 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>title>
    7. <style>
    8. .box {
    9. margin: 20px;
    10. height: 100px;
    11. width: 100px;
    12. border: 2px solid grey;
    13. border-radius: 10px;
    14. padding: 10px;
    15. box-sizing: border-box;
    16. /* 容器内元素使用flex布局 */
    17. display: flex;
    18. /* 将主轴改为纵向 */
    19. flex-direction: column;
    20. /* 主轴(纵向)绝对均匀对齐(子元素间距以及两端边缘间距都相等) */
    21. justify-content: space-evenly;
    22. }
    23. .row1 {
    24. /* 每行内元素使用flex布局 */
    25. display: flex;
    26. /* 主轴(横向)相对均匀对齐 */
    27. justify-content: space-between;
    28. }
    29. .row2 {
    30. /* 每行内元素使用flex布局 */
    31. display: flex;
    32. /* 主轴(横向)居中对齐 */
    33. justify-content: center;
    34. }
    35. .point {
    36. border-radius: 50%;
    37. height: 25px;
    38. width: 25px;
    39. background: black;
    40. }
    41. style>
    42. head>
    43. <body>
    44. <div class="box">
    45. <div class="row1">
    46. <div class="point">div>
    47. <div class="point">div>
    48. div>
    49. <div class="row2">
    50. <div class="point">div>
    51. div>
    52. <div class="row1">
    53. <div class="point">div>
    54. <div class="point">div>
    55. div>
    56. div>
    57. body>
    58. html>

    1. 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>title>
    7. <style>
    8. .box {
    9. margin: 20px;
    10. height: 100px;
    11. width: 100px;
    12. border: 2px solid grey;
    13. border-radius: 10px;
    14. padding: 10px;
    15. box-sizing: border-box;
    16. /* 容器内元素使用flex布局 */
    17. display: flex;
    18. /* 将主轴改为纵向 */
    19. flex-direction: column;
    20. /* 主轴(纵向)相对均匀对齐 */
    21. justify-content: space-between;
    22. }
    23. .row {
    24. /* 每行内元素使用flex布局 */
    25. display: flex;
    26. /* 主轴(横向)绝对均匀对齐 */
    27. justify-content: space-evenly;
    28. }
    29. .point {
    30. border-radius: 50%;
    31. height: 20px;
    32. width: 20px;
    33. background: black;
    34. }
    35. style>
    36. head>
    37. <body>
    38. <div class="box">
    39. <div class="row">
    40. <div class="point">div>
    41. <div class="point">div>
    42. <div class="point">div>
    43. div>
    44. <div class="row">
    45. <div class="point">div>
    46. <div class="point">div>
    47. <div class="point">div>
    48. div>
    49. <div class="row">
    50. <div class="point">div>
    51. <div class="point">div>
    52. <div class="point">div>
    53. div>
    54. div>
    55. body>
    56. html>

  • 相关阅读:
    JavaScript 教程---互联网文档计划
    jQuery【事件】
    Nacos从0到1(基础篇)
    计算机毕业设计(附源码)python疫情隔离便民系统
    Java语言Map中GetOrDefault方法的使用
    小程序源码:全新外卖侠cps5.6全套微信小程序源码下载-多玩法安装简单
    C#:画许多圆
    快速搭建Linux网站,并利用内网穿透实现宝塔面板的公网访问【内网穿透】
    Web前端中横线:深入探索与实际应用
    沁恒 CH32V208(四): CH32V208 网络DHCP示例代码分析
  • 原文地址:https://blog.csdn.net/m0_60559048/article/details/136587541