html - Block A 全高在左侧,带 flex

标签 html css flexbox

<分区>

我的界面将 block A 保持在左侧(全高)。我知道我的实际实现是错误的,因为 block A 没有正确占用整个高度空间,但我是 flex 属性的新手。

如何让 block A 在左侧完全高度?

jsfiddle:my implementation

.container,
html,
body {
  height: 100%;
  margin: 0;
}

.container {
  display: flex;
  flex-direction: column;
}

.item,
.block {
  background-color: red;
  margin: 5px;
  padding: 5px;
}

.itemA {
  width: 30px;
  height: 100vh;
  float: left;
}

.itemB {
  flex: 0 0 100px;
  display: flex;
}

.block {
  flex: 1;
  display: none;
}

.itemD {
  flex: 1;
}

.itemB1,
.itemB2,
.itemB3 {
  flex: 1;
}
<div class="item itemA">
    A
  </div>

  <div class="container">

    <div class="itemB">
      <div class="item itemB1">
        B1
      </div>
      <div class="item itemB2">
        B2
      </div>
      <div class="item itemB3">
        B3
      </div>
    </div>

    <div class="item itemD">
      D
    </div>

  </div>

最佳答案

您还必须适应应用于该元素的填充和边距。使用 calc()

尝试以下操作

.container,
html,
body {
  height: 100%;
  margin: 0;
}

.container {
  display: flex;
  flex-direction: column;
}

.item,
.block {
  background-color: red;
  margin: 5px;
  padding: 5px;
}

.itemA {
  width: 30px;
  height: calc(100vh - 20px);
  float: left;
}

.itemB {
  flex: 0 0 100px;
  display: flex;
}

.block {
  flex: 1;
  display: none;
}

.itemD {
  flex: 1;
}

.itemB1,
.itemB2,
.itemB3 {
  flex: 1;
}
<div class="item itemA">
  A
</div>

<div class="container">

  <div class="itemB">
    <div class="item itemB1">
      B1
    </div>
    <div class="item itemB2">
      B2
    </div>
    <div class="item itemB3">
      B3
    </div>
  </div>

  <div class="block blockB1">
    Block B1
  </div>
  <div class="block blockB2">
    Block B2
  </div>
  <div class="block blockB3">
    Block B3
  </div>
  <div class="block blockD">
    Block D
  </div>

  <div class="item itemD">
    D
  </div>

</div>

关于html - Block A 全高在左侧,带 flex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58352195/

相关文章:

html - 跨浏览器 CSS 复选框问题

html - 即使标题很长,如何自动将文本放入框中

css - 滚动条没有出现在 FF 中,而是出现在 Chrome 中

javascript - 如何在列数为 2 的弹出联系表单中设置有序字段

css - Angular Material 设置颜色 primary, accent, warn

html - 为什么我的 flex wrap 实际上没有将我的元素堆叠在一起?

html - 显示 : inline doesn't work properly with div

html - 当包裹在 "block"元素中时,一切都消失了

css - 拉伸(stretch) CSS Flexbox 网格中的元素

javascript - 使用 Flexbox 时模拟 "Card Layout"