flex布局,align-self对齐方式不对

发布于 2022-09-04 23:49:04 字数 1210 浏览 7 评论 0

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>display</title>
</head>
<body>
    <div class="box dad">
        <div class="item son">1</div>
        <div class="item son">2</div>
    </div>
</body>
</html>

<style>
    .dad{
        width: 500px;
        height: 500px;
        background-color: #999;
        margin: 0 auto;
    }
    .son{
        width: 50px;
        height: 50px;
        line-height: 50px;
        border-radius: 25px;
        text-align: center;
        font-weight: 700;
        font-size: 17px;
        background-color: #ff0000;
    }
    .box{
        display: flex;
    }
    .item:nth-child(2) {
        align-self: center;
    }
</style>

想要达到的效果是:

clipboard.png

但是实际运行的结果是:

clipboard.png

为什么第2个圆点没有居中?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

So要识趣 2022-09-11 23:49:04

.box{

    display: flex;
    justify-content: space-between;
}
谜泪 2022-09-11 23:49:04

不需要 align-self 属性,子节点的居中对齐等排列方式应尽量在父节点中指定。在这里为父节点添加 justify-content: center; align-items: center; 属性即可。

中性美 2022-09-11 23:49:04

可以设置对齐方式:flex-direction:column;
再对2号圆进行对齐:align-self:center;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文