将图像放入Flexbox细胞比例尺中而不定义尺寸?将图像制作在flexbox细胞比例尺中...
我在flexbox中构建了一行,它有一个图像作为顶部元素,然后是下面文本的div容器。相当标准的东西。该行正在前往一个cms,因此,这就是问题所在。
客户端将能够改变图像,因此我不知道图像有多大。因此设置任何宽度或高度属性是不可能的。此外,该行被设计为适合任何屏幕,因此在更大的屏幕上,我根本不知道容器需要多宽。
我在codepen上做实验,但是当图像很大时,它似乎强制下一个对象向下。我显然喜欢将图像缩放到最适合父容器的位置。
HTML
<section class="cards">
<article class="card">
<a href="#">
<figure class="thumbnail">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1047234/library-placehold.jpg" alt="">
</figure>
<div class="card-content">
<h2>Title</h2>
<p>Placeholder text</p>
</div><!-- CLOSE CARD CONTENT -->
</a><!-- CLOSE LINK -->
</article><!-- CLOSE ARTICLE -->
<article class="card">
<a href="#">
<figure class="thumbnail">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1047234/library-placehold.jpg" alt="">
</figure>
<div class="card-content">
<h2>Title</h2>
<p>Placeholder text</p>
</div><!-- CLOSE CARD CONTENT -->
</a><!-- CLOSE LINK -->
</article><!-- CLOSE ARTICLE -->
<article class="card">
<a href="#">
<figure class="thumbnail">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1047234/library-placehold.jpg" alt="">
</figure>
<div class="card-content">
<h2>Title</h2>
<p>Placeholder text</p>
</div><!-- CLOSE CARD CONTENT -->
</a><!-- CLOSE LINK -->
</article><!-- CLOSE ARTICLE -->
</section><!-- CLOSE SECTION -->
SASS
section.cards
width: 90%
margin: 50px auto
display: flex
flex-wrap: wrap
justify-content: space-between
flex-direction: row
article.card
background: #ffffff
margin-bottom: 2em
flex: 0 1 calc(33% -1em)
a
color: #000000
text-decoration: none
&:hover
box-shadow: 3px 3px 8px hsl(0, 0%, 70%)
.thumbnail
display: flex
justify-content: center
align-items: center
img
height: 100%
width: 100%
object-fit: contain
.card-content
padding: 1.4em
h2
margin-top: 0
margin-bottom: .5em
font-weight: normal
p
font-size: 95%