弹性布局

45 阅读1分钟

运行效果:

f9a660badaf2fc971d3fa519d7694bd.png

可以根据弹性布局分布中间那个圆点的位置

开启flex布局:

  displayflex

flex-direction 属性指定了弹性子元素在父容器中的位置。

flex-direction的值有:

  • row:横向从左到右排列(左对齐),默认的排列方式。
  • row-reverse:反转横向排列(右对齐,从后往前排,最后一项排在最前面。
  • column:纵向排列。
  • column-reverse:反转纵向排列,从后往前排,最后一项排在最上面。

代码:

 <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>弹性布局</title>
        <style>
            *{
                margin: 0px;
                padding: 0px;
            }
            ul{
                width: 200px;
                height: 200px;
                border-radius: 10%;
                background-color: black;
                display: flex;
                flex-direction:reverse ;
                justify-content: space-between;
                align-items: center;

            }
            li{
                width: 50px;
                height: 50px;
                border-radius: 50%;
                background-color: white;
                list-style: none;
            }
            #d{
                display: flex;
                justify-content: space-between;
                align-items: start;
            }
        </style>
    </head>
    <body>
        <ul>
            <div id="d">
                <li></li>
                <li></li>
            </div>
            <div id="d">
                <li></li>
                <li></li>
            </div>
        </ul>   
    </body>
    </html>