【发布时间】:2017-11-14 22:47:29
【问题描述】:
图片标题在图片具有不同高度的图库中由 flexbox 底部对齐。如何实现第一行文本(标题)水平对齐?
<style type="text/css">
* {
box-sizing: border-box; }
.flex-container {
display: flex;
flex-wrap: wrap; }
.flex-item {
width: 50%;
padding: 20px;
display: flex;
flex-direction: column; }
.flex-item img {
width: 100%;
height: auto; }
.flex-image {
flex: 1 0 auto; }
</style>
<div class="flex-container">
<div class="flex-item">
<div class="flex-image">
<img src="img-1.jpg" alt="" />
</div>
<p>title</p>
</div>
<div class="flex-item">
<div class="flex-image">
<img src="img-2.jpg" alt="" />
</div>
<p>title<br>Lorem ipsum dolor sit amet.</p>
</div>
</div>
请查看我的密码笔:https://codepen.io/tinusmile/pen/MoeORG
非常感谢!
【问题讨论】:
-
我刚刚用第二个选项更新了我的答案,链接到我在您上一个问题中的答案