html - 增加跨度高度

标签 html css flexbox

如何获得绿色div具有与红色 div 相同的可变高度? 这意味着当绿色文本增长时,红色框的高度也会增长到与绿色框相同。 我知道我可以删除 span来自.aaa ,但对于其他代码影响,这不是可行的解决方案。 .aaa span必须保留。

.aaa span {
  display: flex;
  padding: 20px;
  font-size: 1.6em;
}

.bbb {
  width: 50%;
  float: left;
  text-align: left;
  color: black;
  background: red;
}

.ccc {
  width: 30%;
  text-align: center;
  background-color: green;
}
<div class="wrapper">
  <div class="aaa"><span class="bbb">Hello hello hello hello hello Hello hello hello hello hellotitle titletitle titletitle titletitle titletitle titletitle title</span>
    <span class="ccc">12345</span>
  </div>
</div>

f F

最佳答案

像这样分割你的第一个 CSS 规则:

.aaa {
  display: flex;
}

.aaa span {
  padding: 20px;
  font-size: 1.6em;
}

flex 属性需要分配给容器,而不是分配给跨度。并且 float 不是必需的。

.aaa {
  display: flex;
}

.aaa span {
  padding: 20px;
  font-size: 1.6em;
}

.bbb {
  width: 50%;
  text-align: left;
  color: black;
  background: red;
}

.ccc {
  width: 30%;
  text-align: center;
  background-color: green;
}
<div class="wrapper">
  <div class="aaa"><span class="bbb">Hello hello hello hello hello Hello hello hello hello hellotitle titletitle titletitle titletitle titletitle titletitle title</span>
    <span class="ccc">12345</span>
  </div>
</div>

关于html - 增加跨度高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47757225/

相关文章:

jquery - 防止子菜单被溢出滚动容器裁剪

转发器控件中的 CSS 样式

html - 全高图像作为文本

javascript - document.preventDefault() 不是我需要的

javascript - 如何在鼠标滚动上加载消息?

html - 大屏幕智能手机的 RWD 失败

html - 使div不展开父级

javascript - 当元素在视口(viewport)中时应用选择器

css - Mixin 大小参数 CSS 问题

html - 使用 flexbox 将元素左对齐和居中对齐