gpt4 book ai didi

html - CSS:使用 flex 进行垂直对齐时遇到问题

转载 作者:太空宇宙 更新时间:2023-11-03 22:46:32 24 4
gpt4 key购买 nike

我正在尝试添加一个类以垂直对齐顶部、中间或底部,但我显然遗漏了一些东西:

.row {
display: flex;
background-color: #f0f0f0;
}
.col-3 {
-ms-flex-preferred-size: 25%;
flex-basis: 25%;
max-width: 25%;
}
[class*='col-'].col-top {
align-items: flex-start;
}
[class*='col-'].col-center {
align-items: center;
}
[class*='col-'].col-bottom {
align-items: flex-end;
}
<div class="row">

<div class="col-3">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div class="col-3 col-center">
middle
</div>
<div class="col-3 col-bottom">
right
</div>

</div>

最佳答案

你的列也需要有 display: flex :)

.row {
display: flex;
background-color: #f0f0f0;
}
.col-3 {
-ms-flex-preferred-size: 25%;
flex-basis: 25%;
max-width: 25%;
display: flex;
}
[class*='col-'].col-top {
align-items: flex-start;

}
[class*='col-'].col-center {
align-items: center;
background: #ff9000;
}
[class*='col-'].col-bottom {
align-items: flex-end;
background: #0099ff;
}
<div class="row">

<div class="col-3">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div class="col-3 col-center">
middle
</div>
<div class="col-3 col-bottom">
right
</div>

</div>

关于html - CSS:使用 flex 进行垂直对齐时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41681453/

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