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个圆点没有居中?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
.box{
不需要
align-self
属性,子节点的居中对齐等排列方式应尽量在父节点中指定。在这里为父节点添加justify-content: center; align-items: center;
属性即可。可以设置对齐方式:flex-direction:column;
再对2号圆进行对齐:align-self:center;