【问题标题】:Nested Grid/Flexbox title pushing content downwards [duplicate]嵌套网格/弹性框标题向下推动内容[重复]
【发布时间】:2018-04-01 03:42:51
【问题描述】:

我正在尝试在网站上构建团队成员列表。并且(总是)这个人的职位很长,正在推动他的职位描述下载。

这导致与其他职位描述不一致,设计师对此非常有强迫症。

到目前为止,我发现的唯一解决方案是将职位描述限制为 3 行:

font-size: 10px;
height: 30px;
line-height: 1;

但是,如果职位名称变成 4 行长,它仍然不能防错。此外,较小的屏幕甚至可能将短文本换行,使其长度超过 4 行。

我研究了使用 CSS 网格的可能性,但没有找到解决这个问题的方法。需要满足这些条件:

  • 图片、名称&标题和描述需要在同一行对齐
  • 四个网格中的每一个都需要具有相同的高度
  • 灵活的文本
  • 如果我们可以在不使用 jQuery 的 MatchHeight 的情况下解决这个问题,那就太好了。

<div class="row small-up-1 medium-up-2 large-up-3">
  <% loop $Collection %>
    <div class="column person">
      <div class="row column">
        <div class="person__photo">
          <img src="$Image.Url" class="person__photo--round" alt="$Name">
        </div>
      </div>
      <div class="row column text-center">
        <h4 class="person__name">$Name</h4>
        <h5 class="person__role">$Role</h5>
      </div>
      <% if $Blurb %>
        <div class="row column person__summary content">$Blurb</div>
      <% end_if %>
    </div>
  <% end_loop %>
</div>

【问题讨论】:

  • 您应该发布足够的代码来重现该问题。这使我们能够更有效地帮助您。
  • 嗨@Michael_B,添加代码供您参考。
  • @JamesWee this post 应该有帮助:)
  • @Danield 非常感谢。这正是我正在寻找的。不幸的是,没有一种所有浏览器都支持的明确(和万无一失)方式。但一切都很好,我得到了我需要的东西。再次感谢您。

标签: css twitter-bootstrap flexbox zurb-foundation css-grid


【解决方案1】:

你能把它们排成一行吗?因此,请执行以下操作:

.headshot, .positionTitle, .description {
	width: 100px;
	min-height: 20px;
	border: solid 1px black;
}

.row {
	display: flex;
	flex-direction: row;
	justify-content: space-evenly;
}
<div class="row"> <!-- Image row -->
	<div class="headshot"></div>
	<div class="headshot"></div>
	<div class="headshot"></div>
	<div class="headshot"></div>
</div>

<div class="row"> <!-- Title row -->
	<div class="positionTitle">Short</div>
	<div class="positionTitle">Short</div>
	<div class="positionTitle">Really really<br><br><br>long</div>
	<div class="positionTitle">Short</div>
</div>

<div class="row"> <!-- Description row -->
	<div class="description"></div>
	<div class="description"></div>
	<div class="description"></div>
	<div class="description"></div>
</div>  

【讨论】:

  • 好主意,但如果我从一个循环中循环所有团队成员,除非我为每个类别(头像、位置、描述)有多个循环,否则我不能这样做,这是一种反模式.
猜你喜欢
  • 1970-01-01
  • 2021-05-23
  • 2018-10-20
  • 2018-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多