html - 在 flex grow 容器中使用 flex 方向列

标签 html css flexbox

<分区>

我需要一个 div 来拥有 display: flexflex-direction: columnflex: 1 .但由于某种原因,该 div 的内容被调整了大小。

使用 display: block 不会调整内容的大小。

 body {
      margin: 0;
      display: flex;
      flex-direction: column;
      height: 100vh;
    }

    header {
      height: 2em;
      background: blue;
    }

    main {
      background: yellow;
      flex: 1;
      overflow-y: auto;
      /* Why display: flex resizes the articles */
      display: flex;
      flex-direction: column;
      /* If you use display: block its working (uncomment to test)*/
      /* display: block; */
    }

    article {
      height: 15em;
      border: 1px solid black;
      margin: 1em;
    }

    footer {
      background: green;
      height: 3em;
    }
    <body>
      <header></header>
      <main>
        <article></article>
        <article></article>
        <article></article>
      </main>
      <footer></footer>
    </body>



   

https://codepen.io/anon/pen/YdewKJ

最佳答案

请在您的 CSS 中添加以下代码:

article {
  flex-shrink: 0;
}

关于html - 在 flex grow 容器中使用 flex 方向列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54021470/

上一篇:php - 提交按钮在 while 循环之外,但在提交表单后它总是四处移动

下一篇:html - Flex/Grid 布局不适用于按钮或字段集元素

相关文章:

css - SVG - 试图弄清楚如何使用 svg 而不是 clipPath 来支持 EDGE

css - Chrome 忽略列布局中的 flex-basis

css - 使用列数时框阴影被切断

php - MySQL/PHP : Looking for matching records from three tables(Forum permissions)

html - 按钮不会对 CSS 中的填充或边距使用react

css - 如何在 google chrome 的开发者工具中显示样式表的路径?

javascript - 链接到特定幻灯片

html - Bootstrap 3 中缩略图列的高度相同

html - 我的 header 包含在我的主标记中

javascript - 如何在文本框中生成用户给定值的索引?