知识分子李云龙 2022-03-23 00:33 采纳率: 0%
浏览 71
已结题

Flex布局中设置了容器留白均分,不能在设置项目居中嘛

问题遇到的现象和发生背景

Flex布局中设置了容器留白均分,不能在设置项目居中

问题相关代码,请勿粘贴截图
<div>
        <a href="">
            <span></span>
        </a>
        <a href="">
            <span></span>
            <span></span>
        </a>
        <a href="">
            <span></span>
            <span></span>
            <span></span>
        </a>
   </div>


a {
    display: flex;
    margin-bottom: 20px;
    position: relative;
    left: 50%;
    top: 200px;
    
    width: 50px;
    height: 50px;
    background-color: aliceblue;
    padding: 10px;
    border-radius: 5px;
}
a span {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: black;
}
a:nth-child(3) {
    flex-direction: column;
}
a:nth-child(3) {
    justify-content: space-evenly;
}

a:nth-child(3) span:nth-child(2) {
    justify-content: center;
    align-items: center;
    background-color: aquamarine;
}

运行结果及报错内容

三个span主轴方向均匀排列,但是第二个不能去中间,第三个不能去最右

我的解答思路和尝试过的方法

添加第二个span的背景颜色是变的,说明是主轴方向的位置属性冲突,但是自学css找不出原因

我想要达到的结果

想做出类似骰子的三点样式。

  • 写回答

3条回答 默认 最新

  • H_四叶草 2022-03-23 09:09
    关注
    
    <style>
        div {
            display: flex;
        }
    a {
        display: flex;
        margin-bottom: 20px;
        /* position: relative; */
        left: 50%;
        top: 200px;
        
        width: 50px;
        height: 50px;
        background-color: aliceblue;
        padding: 10px;
        border-radius: 5px;
    }
    a span {
        width: 12px;
        height: 12px;
        border-radius: 50%;
        background-color: black;
    }
    a:nth-child(3) {
        flex-direction: column;
    }
    a:nth-child(3) {
        justify-content: space-evenly;
    }
     
    a:nth-child(3) span:nth-child(2) {
        justify-content: center;
        align-items: center;
        background-color: aquamarine;
    }
     
    </style>
    <div>
            <a href="">
                <span></span>
            </a>
            <a href="">
                <span></span>
                <span></span>
            </a>
            <a href="">
                <span></span>
                <span></span>
                <span></span>
            </a>
       </div>
     
     
    
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 7月16日
  • 创建了问题 3月23日