当文本到达图像的右侧时,如何将文本包裹在figcaption
中?
.flex-container {
padding: 0;
margin: 0;
list-style: none;
display: flex;
flex-flow: row wrap;
justify-content: flex-start;
}
.flex-figure-item {
padding: 5px;
margin-top: 10px;
line-height: 10px;
font-weight: bold;
font-size: 1em;
}
figcaption {
color: black;
}

<div class="flex-container">
<figure class="flex-figure-item">
<img src="https://placehold.it/150x200" alt="placeholder">
<figcaption>Short, John</figcaption>
</figure>
<figure class="flex-figure-item">
<img src="https://placehold.it/150x200" alt="placeholder">
<figcaption>WrapMe, Longname should not go past right side of image</figcaption>
</figure>
<figure class="flex-figure-item">
<img src="https://placehold.it/150x200" alt="placeholder">
<figcaption>Short, Sally</figcaption>
</figure>
</div>
&#13;
以下是笔:http://codepen.io/mjankowski/pen/pbzejy
在上面的情况中,第二个图形标题远远超出图像的右侧。我希望它包含在&#34; Longname&#34;。
之后另外,请接受更简单方法的建议。我只是希望图像/标题整洁。
谢谢, 马特
答案 0 :(得分:2)
一种方法是使figure
个元素成为容器,并将其对齐设置为flex-direction: column
。这样可以更好地控制整个元素的宽度。
.flex-container {
padding: 0;
margin: 0;
list-style: none;
display: flex;
flex-flow: row wrap;
justify-content: flex-start;
}
.flex-figure-item {
padding: 5px;
margin-top: 10px;
line-height: 10px;
font-weight: bold;
font-size: 1em;
display: flex; /* NEW */
flex-direction: column; /* NEW */
width: 150px; /* NEW */
}
figcaption {
color: black;
}
<div class="flex-container">
<figure class="flex-figure-item">
<img src="https://placehold.it/150x200" alt="placeholder">
<figcaption>Short, John</figcaption>
</figure>
<figure class="flex-figure-item">
<img src="https://placehold.it/150x200" alt="placeholder">
<figcaption>WrapMe, Longname should not go past right side of image</figcaption>
</figure>
<figure class="flex-figure-item">
<img src="https://placehold.it/150x200" alt="placeholder">
<figcaption>Short, Sally</figcaption>
</figure>
</div>