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

查看:274
本文介绍了flex布局,align-self对齐方式不对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

<!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>

想要达到的效果是:

但是实际运行的结果是:

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

解决方案

.box{

    display: flex;
    justify-content: space-between;
}

这篇关于flex布局,align-self对齐方式不对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆