gpt4 book ai didi

html - Flexbox align-self 被忽略

转载 作者:太空宇宙 更新时间:2023-11-03 21:13:25 25 4
gpt4 key购买 nike

align-self 的文档状态:

The align-self CSS property aligns flex items of the current flex line overriding the align-items value.

然而,这不会发生:

.example {
display: flex;
align-items: center;
border: 1px solid blue;
height: 8ex;
}

.example > div {
border: 1px solid red;
}

#a > div:last-child {
align-self: top;
}

#b > div:last-child {
align-self: center;
}

#c > div:last-child {
align-self: bottom;
}
<body>
<div id="a" class="example"><div>1</div><div>2</div></div>
<div id="b" class="example"><div>1</div><div>2</div></div>
<div id="c" class="example"><div>1</div><div>2</div></div>
</body>

文档还说:

If any of the item's cross-axis margin is set to auto, then align-self is ignored. The property doesn't apply to block-level boxes, or to table cells.

但是,这些都不起作用:

  • 向子 div 显式添加 margin:0
  • display:inline 添加到子 div
  • div 更改为 span

为什么 align-self 不起作用?

最佳答案

topbottom 不是 align-self 的有效值。使用 flex-startflex-end 代替:

.example {
display: flex;
align-items: center;
border: 1px solid blue;
height: 8ex;
}

.example > div {
border: 1px solid red;
}

#a > div:last-child {
align-self: flex-start;
}

#b > div:last-child {
align-self: center;
}

#c > div:last-child {
align-self: flex-end;
}
<body>
<div id="a" class="example"><div>1</div><div>2</div></div>
<div id="b" class="example"><div>1</div><div>2</div></div>
<div id="c" class="example"><div>1</div><div>2</div></div>
</body>

关于html - Flexbox align-self 被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44396753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com