【发布时间】:2017-01-04 22:18:17
【问题描述】:
我想知道在您使用 flexbox 并尝试使用 align-items: baseline 时是否有办法覆盖/指定基线。
我有一个 flex 容器,其中包含几个不同的 div(即标题、img、正文、描述)。
有了这些弹性项目,我想以具有.flex-body 的 div 的基线为中心。它应该以“居中”文本的下划线为中心。
这就是我目前的尝试正在产生的结果。
我希望它看起来像这样,其中每一行都有以“此处中心”下划线为中心的弹性项目 --- 没有完全对齐,因为我只是在那里粘贴边距以使图片看起来有点像就像我想要的一样:P
如果我需要将项目与基线对齐,我如何使用它将我的 flex div 居中到项目中间的下划线?
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-align-items: baseline;
align-items: baseline;
width: 400px;
height: 350px;
background-color: lightgrey;
flex-wrap: wrap;
}
.flex-item {
background-color: cornflowerblue;
width: 100px;
margin: 10px;
display: inline-flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
}
.flex-body {
border-bottom: 1px solid #fff;
}
.flex-img {
justify-content: center;
align-items: center;
}
<div class="flex-container">
<div class="flex-item">
<div class="flex-title">
flex title1
</div>
<div class="flex-img">
<img src='http://dummyimage.com/90x40/000/ffffff&text=hi'>
</div>
<div class="flex-body">
center here
</div>
<div class="flex-body-more">
more text
</div>
</div>
<div class="flex-item">
<div class="flex-title">
flex title1 longer title
</div>
<div class="flex-img">
<img src='http://dummyimage.com/40x40/000/ffffff&text=hi'>
</div>
<div class="flex-body">
center here
</div>
<div class="flex-body-more">
more text
</div>
</div>
<div class="flex-item">
<div class="flex-title">
flex title1
</div>
<div class="flex-img">
<img src='http://dummyimage.com/40x90/000/ffffff&text=hi'>
</div>
<div class="flex-body">
center here
</div>
<div class="flex-body-more">
more text more text more text
</div>
</div>
<div class="flex-item">
<div class="flex-title">
flex title1
</div>
<div class="flex-img">
<img src='http://dummyimage.com/90x40/000/ffffff&text=hi'>
</div>
<div class="flex-body">
center here
</div>
<div class="flex-body-more">
more text
</div>
</div>
<div class="flex-item">
<div class="flex-title">
flex title1
</div>
<div class="flex-img">
<img src='http://dummyimage.com/40x50/000/ffffff&text=hi'>
</div>
<div class="flex-body">
center here
</div>
<div class="flex-body-more">
more text
</div>
</div>
</div>
【问题讨论】:
标签: html css alignment flexbox