【发布时间】:2018-11-27 21:19:48
【问题描述】:
我刚刚注意到align-self 属性的一些值,这是我以前从未见过的。什么是start、end、self-start和self-end,它们与flex-start和flex-end有什么区别?
当我使用 flexbox 时,我经常提到 the guide at CSS-Tricks,但它没有提到这些值。我在 MDN 上阅读了documentation for align-self,但对值的单行描述不足以让我理解。
我想我也许可以玩弄这些值来弄清楚,但它们似乎都做同样的事情......
.container {
display: flex;
justify-content: center;
align-items: center;
background: papayawhip;
width: 400px;
height: 200px;
margin: 1rem auto;
box-shadow: 0px 0px 5px 1px rgba(0, 0, 0, 0.2);
border-radius: 0.5em;
}
.block {
color: white;
font-size: 3em;
font-family: sans-serif;
padding: 0.5rem;
margin: 0.5rem;
display: flex;
justify-content: center;
align-items: center;
}
.block-1 {
background: red;
}
.block-2 {
background: orange;
}
.block-3 {
background: gold;
}
.block-4 {
background: green;
}
.block-5 {
background: blue;
}
.block-2 {
align-self: flex-start;
}
.block-3 {
align-self: start;
}
.block-4 {
align-self: self-start;
}
<div class="container">
<div class="block block-1">1</div>
<div class="block block-2">2</div>
<div class="block block-3">3</div>
<div class="block block-4">4</div>
<div class="block block-5">5</div>
</div>
【问题讨论】: