【问题标题】:How to achieve Wordwrap of List Elements inside a Flexbox Layout如何在 Flexbox 布局中实现列表元素的自动换行
【发布时间】:2018-09-16 15:56:36
【问题描述】:

以下是根据我的问题的元素目前的样子: Flexbox Layout

我想要实现的是,如果无序列表元素内的文本太长,则将其换行到下一行。现在发生的情况是,整个列表跳转到新行(参见链接图像中的第二个示例)。

我希望列表保持在同一行的图像旁边(直到到达某些媒体查询以中断flex-direction: column)。

任何可能的解决方案?

.team-row {
  display: -webkit-flex;
  /* Safari */
  -webkit-flex-flow: row wrap;
  /* Safari 6.1+ */
  display: flex;
  flex-flow: row wrap;
  margin-top: 1em;
  border: 1px solid #efefef;
  padding: 5px;
}

.team-header {
  padding: 8px;
  background-color: #F6B80B;
  width: 100%;
}
<div class="team-row">
  <strong class="team-header">Wolfgang Niepel</strong>
  <img class="team-image" src="http://wp.fahrschuleniepel.de/wp-content/uploads/2018/09/image.png" alt="Wolfgang Niepel" width="100" height="133">
  <ul class="team-description">
    <li>Fahrlehrer seit: 1964</li>
    <li>selbstständig seit: 1968</li>
    <li>sonstiges: Gründung der Fahrschule Niepel am 01.12.1968.</li>
  </ul>
</div>

<div class="team-row">
  <strong class="team-header">Jens Niepel</strong>
  <img class="team-image" src="http://wp.fahrschuleniepel.de/wp-content/uploads/2018/09/jens_niepel_100.jpg" alt="Jens Niepel" width="100" height="133">
  <ul class="team-description">
    <li>Fahrlehrer seit: 1983</li>
    <li>bei Fahrschule Niepel seit: 1983</li>
    <li>sonstiges: Seit 2001 leite ich unser Büro und bin Ihr Ansprechpartner zu allen Fragen rund um Ihre Ausbildung.</li>
  </ul>
</div>

【问题讨论】:

  • 一定要用flex-flow: row wrap;吗?为什么不用divdisplay: flex 将“列”部分包裹起来,仅此而已?

标签: html css flexbox word-wrap


【解决方案1】:

flex: 1; 添加到.team-description

这将设置:

flex-grow: 1;
flex-shrink: 1;
flex-basis: 0%;

【讨论】:

  • 完美运行。你能解释一下为什么吗?它只是让 ul 和内部元素增长而不管 Image 对吗?
  • 看看this tool,一个很好的起点去玩,设计和理解flexbox
猜你喜欢
  • 2022-11-15
  • 1970-01-01
  • 1970-01-01
  • 2021-07-06
  • 1970-01-01
  • 1970-01-01
  • 2015-06-26
  • 1970-01-01
相关资源
最近更新 更多