CSS - height:calc(100% - Nem)在flex内部时不起作用

问题描述 投票:0回答:1

我有三排:固定,流体,固定。这三行在一起是100%高度,并且必须始终在页面上可见而不滚动。在流体排中,我有一个必须占据100%高度的模块。除了在模块中我需要使用overflow:auto。这是我的代码:

    * {
      box-sizing: border-box;
    }
    html, body {
      height: 100%;
      padding:0;
      margin:0;
    }
    
    .flexbox-parent
    {
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: stretch;
        align-content: stretch;
    }
    
    .flexbox-item-grow
    {
        flex: 1;
    }
    
    .fill-area
    {
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: stretch; 
        align-content: stretch;
        
    }
    
    div.module {
       width:100%;
       height:100%;
       background-color:yellow;
    }
    
    div.scrolling {
        height:calc(100% - 4em);
        overflow:auto;
    }
    
    div.header, div.footer {
      height: 2em;
      background:cyan;
    }
    <div class="flexbox-parent">
        <div>
            TOP
        </div>
        <div class="fill-area flexbox-item-grow">
            <div class="flexbox-item-grow">
    			<div class="module">
    				<div class="header"></div>
    				<div class="scrolling">
    				    <p> Some Text</p>
    				    <p> Some Text</p>
    				    <p> Some Text</p>
    				    <p> Some Text</p>
    				    <p> Some Text</p>
    				    <p> Some Text</p>
    				    <p> Some Text</p>
    				    <p> Some Text</p>
    				    <p> Some Text</p>
    				    <p> Some Text</p>
    				    <p> Some Text</p>
    				</div>
    				<div class="footer"></div>
    			</div>
            </div>
        </div>
        <div>
            BOTTOM
        </div>
    </div>

这是fiddle。请问谁知道,帮助我解决这个问题。

html css css3 flexbox
1个回答
1
投票

您可以在滚动元素上使用overflow: auto,但您还需要在以前的父元素上添加overflow: hidden,您还需要使用flex: 1

* {
  /* So 100% means 100% */
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  padding: 0;
  margin: 0;
}
.flexbox-parent {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.flexbox-item-grow, .module{
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: hidden;
}

.scrolling {
  overflow-y: auto;
  background: yellow;
  flex: 1;
}
.header,
.footer {
  background: cyan;
  height: 2em;
}
<div class="flexbox-parent">
  <div>
    TOP
  </div>
  <div class="fill-area flexbox-item-grow">
    <div class="flexbox-item-grow">
      <div class="module">
        <div class="header"></div>
        <div class="scrolling">
          <p> Some Text</p>
          <p> Some Text</p>
          <p> Some Text</p>
          <p> Some Text</p>
          <p> Some Text</p>
          <p> Some Text</p>
          <p> Some Text</p>
          <p> Some Text</p>
          <p> Some Text</p>
          <p> Some Text</p>
          <p> Some Text</p>
        </div>
        <div class="footer"></div>
      </div>
    </div>
  </div>
  <div>
    BOTTOM
  </div>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.