您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

将标题限制为图像的宽度

将标题限制为图像的宽度

一种方法是使您的figure@H_404_2@元素具有弹性容器,并将其对齐方式设置为flex-direction: column@H_404_2@。这样可以更好地控制整个元素的宽度。

.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>
@H_404_2@
其他 2022/1/1 18:18:13 有512人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶