【发布时间】:2019-07-13 08:02:54
【问题描述】:
我正在尝试实现一个 flexbox,该行将所有标题排成一行。要求:
- 图像的高度不一定相同
- 描述并不总是相同的高度
- 标题可以是 1 行,也可以是 3 行(取决于长度)
这是一个简单的小提琴:
https://jsfiddle.net/youradds/r56j4uLe/6/
如您所见,这就是您所得到的:
这就是我所追求的:
我的SCSS是:
#item-wrapper {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
.item-block {
background: yellow;
flex-grow: 0;
width: 350px;
margin: 2rem 1rem;
display: flex;
flex-direction: column;
justify-content: space-between;
align-content: center;
align-items: center;
.what-logo {
img {
max-height: 100%;
}
}
.text-info {
flex-grow: 1;
.desc {
padding: 1rem;
}
h2 {
flex-grow: 0;
}
}
.action-button {
margin: 0 auto;
}
}
}
.pure-img {
max-width: 100%;
height: auto;
display: block;
}
..并测试 HTML:
<div id="item-wrapper">
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/3/3-1562951826-3.png" class="pure-img">
</div>
<div class="text-info">
<h2>Zydrunas Savickas Seminar</h2>
<div class="desc">Bodywise Gym and Studios are proud to announce we are bringing the greatest strongman Zydrunas Savickas (Big Z) to Horsham for a seminar.</div>
</div>
<a href="https://yogida.co.uk/collections/events/products/zydrunas-savickas-big-z-seminar" class="action-button">Find out more »</a>
</div>
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/7/7-1562936970-7.jpg" class="pure-img">
</div>
<div class="text-info">
<h2>Class for mums</h2>
<div class="desc">Join Quick HIIT</div>
</div>
<a href="" class="action-button">Find out more »</a>
</div>
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/6/6-1562936464-6.png" class="pure-img">
</div>
<div class="text-info">
<h2>Gratitude Day</h2>
<div class="desc">To spread the positivity you can bring a training partner along to workout with you or to attend one of our classes.</div>
</div>
<a href="" class="action-button">Find out more »</a>
</div>
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/4/4-1562951950-4.jpg" class="pure-img">
</div>
<div class="text-info">
<h2>The experience of non-duality</h2>
<div class="desc">Yoga & meditation workshop with Indian Spiritual Master Acharya Shree Shankar </div>
</div>
<a href="https://yogida.co.uk/collections/workshops" class="action-button">Find out more »</a>
</div>
</div>
重要提示:这是一种响应式设计,因此我无法在图像 div 上设置高度(即 min-height 600px),因为虽然这种排序是在更宽的屏幕上进行的:
...但是在较小的屏幕上,它会缩小到每行 1 个元素 - 这意味着我们在图像和具有较小图像的条目的标题之间有大量的填充:
【问题讨论】: