css - 如何使用 CSS flex 从父 DIV 到子 DIV 获得 100% 高度

标签 css flexbox

在示例代码块中,有一个 DIV 名称“left-line”(红色线)。我需要根据“内容”DIV 的高度拉伸(stretch)该 DIV 的高度。

拜托,我需要在没有 CSS“position”和“border”属性的情况下实现这一点。我正在使用 CSS flex。

.parent {
  display: -webkit-flex;
  /* Safari */
  display: flex;
  box-sizing: border-box;
  background-color: orange;
}

.left-line {
  width: 10px;
  height: 100%;
  background-color: red;
}

.content {
  flex: 1;
  padding: 0 0 0 14px;
  letter-spacing: 1px;
  line-height: 18px;
}
<div class="parent">
  <div class="left-line">s</div>
  <div class="content">
    <p>Lorem Ipsum is simply dummy text</p>
    <p>Lorem Ipsum is simply dummy text of the printing...</p>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
  </div>
</div>

最佳答案

从 .left-line 类中删除 height:100%

.parent {
  display: -webkit-flex;
  /* Safari */
  display: flex;
  box-sizing: border-box;
  background-color: orange;
}

.left-line {
  width: 10px;
  background-color: red;
}

.content {
  flex: 1;
  padding: 0 0 0 14px;
  letter-spacing: 1px;
  line-height: 18px;
}
<div class="parent">
  <div class="left-line">s</div>
  <div class="content">
    <p>Lorem Ipsum is simply dummy text</p>
    <p>Lorem Ipsum is simply dummy text of the printing...</p>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
  </div>
</div>

关于css - 如何使用 CSS flex 从父 DIV 到子 DIV 获得 100% 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50735415/

相关文章:

css - flexbox 元素容器中的流程问题

html - 你如何使用 Flexbox 拉伸(stretch)和居中元素?

html - Flexbox 将一个元素居中对齐,另一个元素在页面底部对齐

javascript - 代码在 jsfiddle 中有效,但在 Lamp Localhost 中无效

css - 关于更改导航栏中事件页面的背景图像的问题

javascript - 带图片背景的点阵线

html - 强制内联 block 导航栏和列表

css - 使用溢出-x : scroll with justify-content: center hides the earlier blocks

jquery - 整个文档在 IE11 中滚动,但不是 Chrome

html - 如何让复选框+标签系列在填充可用宽度的同时垂直堆叠?