Flexbox的百分比高度

真二山

我试图理解为什么80%和90%的高度似乎不起作用。我希望文本能适合我,但是即使我将容器高度设置为100%或calc(100vh - 150px),尽管它确实增加了,但也没有达到我期望的值。下面是问题的图片。

示范

* {
  margin: 0;
}
html,
body {
  height: 100%;
}
#bigwrap {
  position: relative;
  height: calc(100vh - 150px);
  width: 100%;
}
.container {
  display: flex;
  position: absolute;
  flex-wrap: wrap;
  flex-direction: row;
  justify-content: center;
  align-items: flex-start;
  width: 80%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 100%;
}
.container img {
  width: 200px;
  height: 200px;
}
.left {
  display: flex;
  flex-flow: column wrap;
  align-items: flex-start;
  justify-content: space-around;
  order: 1;
  background: red;
  flex-basis: 100%;
  height: 100%;
}
.left img {
  max-width: 100%;
}
.middle {
  display: flex;
  flex-flow: column wrap;
  align-content: flex-start;
  justify-content: space-around;
  order: 3;
  background: green;
  flex-basis: 100%;
  height: 100%;
}
.right {
  text-align: center;
  order: 2;
  background: yellow;
  flex-basis: 100%;
  height: 100%;
}
.box {
  display: flex;
  flex-flow: row wrap;
  align-items: flex-start;
  justify-content: flex-start;
  height: 200px;
  width: 200px;
}
@media screen and (min-width: 600px) {
  .container {
    flex-wrap: nowrap;
  }
  .left {
    flex-basis: 1;
    order: 1;
  }
  .middle {
    flex-basis: 1;
    order: 2;
  }
  .right {
    flex-basis: 1;
    order: 3;
  }
}
<div id="bigwrap">
  <div class="container">
    <div class="left">
      <img src="cat1.jpeg" alt="cat">
      <img src="cat1.jpeg" alt="cat">
    </div>
    <div class="middle">
      <div class="box">
        <p>
          This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text.
          This is text. This is text. This is text. This is text. This is text. This is text.
        </p>
      </div>
      <div class="box">
        <p>
          This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text.
          This is text. This is text. This is text. This is text. This is text. This is text.
        </p>
        <p>
          This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text.
          This is text. This is text. This is text. This is text. This is text. This is text.
        </p>
      </div>
    </div>
    <div class="right">
      <p>texteiehiefief texteiehiefief texteiehiefief texteiehiefief</p>
      <p>texteiehiefief texteiehiefief texteiehiefief texteiehiefief</p>
      <p>texteiehiefief texteiehiefief texteiehiefief texteiehiefief</p>
    </div>
  </div>

迈克尔·本杰明(Michael Benjamin)

* {
    margin: 0;
}

html,
body {
    height: 100%;
}

#bigwrap {
    position: relative;
    height: 100%;
}

.container {
 display: flex;
 position: absolute;
 flex-wrap: wrap;
 justify-content: center;
 align-items: flex-start;
 height: 100%;
 width: 80%;
 top: 50%;
 left: 50%;
 transform: translate(-50%,-50%); /* http://stackoverflow.com/q/36817249/3597276 */
}

.container img {
    width: 200px;
    height: 200px;
}

.left {
    display: flex;
    flex-flow: column wrap;
    align-items: flex-start;
    justify-content: space-around;
    order: 1;
    background: red;
    flex-basis: 100%;
    height: 100%;
}

.left img {
    max-width: 100%;
}

.middle {
    display: flex;
    flex-flow: column wrap;
    order: 3;
    background: green;
    flex-basis: 100%;
    height: 100%;
}

.right {
    text-align: center;
    order: 2;
    background: yellow;
    flex-basis: 100%;
    height: 100%;
}

.box {
    /* height: 200px;          Remove. This limits the height of the paragraph */
    width: 200px;
}

.box > p {
    margin-bottom: 25px;       /* create separation between text boxes */
}

@media screen and (min-width: 600px) {
    .container {
        flex-wrap: nowrap;
    }
    .left {
        flex-basis: 1;
        order: 1;
    }
    .middle {
        flex-basis: 1;
        order: 2;
    }
    .right {
        flex-basis: 1;
        order: 3;
    }
}
<div id="bigwrap">
  <div class="container">
    <div class="left">
      <img src="cat1.jpeg" alt="cat">
      <img src="cat1.jpeg" alt="cat">
    </div>
    <div class="middle">
      <div class="box">
        <p>
          This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text.
          This is text. This is text. This is text. This is text. This is text. This is text.
        </p>
      </div>
      <div class="box">
        <p>
          This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text.
          This is text. This is text. This is text. This is text. This is text. This is text.
        </p>
        <p>
          This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text.
          This is text. This is text. This is text. This is text. This is text. This is text.
        </p>
      </div>
    </div>
    <div class="right">
      <p>texteiehiefief texteiehiefief texteiehiefief texteiehiefief</p>
      <p>texteiehiefief texteiehiefief texteiehiefief texteiehiefief</p>
      <p>texteiehiefief texteiehiefief texteiehiefief texteiehiefief</p>
    </div>
  </div>

jsFiddle

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

CSS百分比高度无效

来自分类Dev

百分比高度没有任何影响

来自分类Dev

具有百分比高度的Div结构

来自分类Dev

在百分比高度容器中使用溢出

来自分类Dev

绝对定位块的百分比高度

来自分类Dev

父级具有最小/最大高度时的CSS百分比高度

来自分类Dev

Div不会填充百分比高度,而是填充像素高度。为什么?

来自分类Dev

CSS-使用CSS的移动屏幕的百分比高度

来自分类Dev

如何在具有百分比高度的div中间垂直对齐文本?

来自分类Dev

可调整大小的div不响应百分比高度

来自分类Dev

SwiftUI通过百分比高度调整VStack的框架大小

来自分类Dev

具有百分比高度的Div不适合

来自分类Dev

如何创建具有百分比高度的固定的,可滚动的div?

来自分类Dev

如何删除innerHeight并添加客户像素/百分比高度?

来自分类Dev

在CSS中,如何计算“ height:auto”父级中的百分比高度?

来自分类Dev

为什么百分比高度在位置固定元素上起作用?

来自分类Dev

如何在 tinyscrollbar 中给 div 元素一个百分比高度?

来自分类Dev

绝对位置,高度百分比和flexbox

来自分类Dev

在WordPress中使用视口高度(vh)显示div标签以显示窗口的百分比高度

来自分类Dev

带有CSS十进制百分比高度的TD单元在Chrome中获取了不正确的实际高度

来自分类Dev

在窗口调整大小时将具有百分比高度的背景图像转换为像素高度

来自分类Dev

Flexbox:如何合并列的百分比,像素和剩余高度?

来自分类Dev

CSS div高度百分比和边距百分比

来自分类Dev

父div的高度百分比未转化为子div的百分比

来自分类Dev

CSS div高度百分比和边距百分比

来自分类Dev

Azure托管计划上的cpu百分比高得莫名其妙

来自分类Dev

标头中的CSS百分比宽度和高度

来自分类Dev

设定百分比时Div的高度变为0

来自分类Dev

将高度设置为宽度的百分比?

Related 相关文章

  1. 1

    CSS百分比高度无效

  2. 2

    百分比高度没有任何影响

  3. 3

    具有百分比高度的Div结构

  4. 4

    在百分比高度容器中使用溢出

  5. 5

    绝对定位块的百分比高度

  6. 6

    父级具有最小/最大高度时的CSS百分比高度

  7. 7

    Div不会填充百分比高度,而是填充像素高度。为什么?

  8. 8

    CSS-使用CSS的移动屏幕的百分比高度

  9. 9

    如何在具有百分比高度的div中间垂直对齐文本?

  10. 10

    可调整大小的div不响应百分比高度

  11. 11

    SwiftUI通过百分比高度调整VStack的框架大小

  12. 12

    具有百分比高度的Div不适合

  13. 13

    如何创建具有百分比高度的固定的,可滚动的div?

  14. 14

    如何删除innerHeight并添加客户像素/百分比高度?

  15. 15

    在CSS中,如何计算“ height:auto”父级中的百分比高度?

  16. 16

    为什么百分比高度在位置固定元素上起作用?

  17. 17

    如何在 tinyscrollbar 中给 div 元素一个百分比高度?

  18. 18

    绝对位置,高度百分比和flexbox

  19. 19

    在WordPress中使用视口高度(vh)显示div标签以显示窗口的百分比高度

  20. 20

    带有CSS十进制百分比高度的TD单元在Chrome中获取了不正确的实际高度

  21. 21

    在窗口调整大小时将具有百分比高度的背景图像转换为像素高度

  22. 22

    Flexbox:如何合并列的百分比,像素和剩余高度?

  23. 23

    CSS div高度百分比和边距百分比

  24. 24

    父div的高度百分比未转化为子div的百分比

  25. 25

    CSS div高度百分比和边距百分比

  26. 26

    Azure托管计划上的cpu百分比高得莫名其妙

  27. 27

    标头中的CSS百分比宽度和高度

  28. 28

    设定百分比时Div的高度变为0

  29. 29

    将高度设置为宽度的百分比?

热门标签

归档