简体   繁体   English

Flex 子项无法在 Flex 容器上使用滚动溢出

[英]Flex child not working with scroll overflow on flex container

My sidebar consists of a flex container with flex-direction of column, then a div containing a table, and a flex container div holding two spans within it.我的侧边栏由一个带有 flex-direction column 的 flex 容器、一个包含表格的 div 和一个包含两个 span 的 flex 容器 div 组成。 For some reason, whenever the table overflows, the div with the spans is cut off and the table can be scrolled (but does not have the spans at the bottom).出于某种原因,每当表格溢出时,带有跨度的 div 就会被切断并且表格可以滚动(但底部没有跨度)。 I've tried several solutions based on what I've read about the issue but none of them seem to work for me and I'm just confused why the entire container won't scroll when there is an overflow.我已经根据我所读到的有关该问题的内容尝试了几种解决方案,但它们似乎都不适合我,我只是很困惑为什么整个容器在溢出时不会滚动。

Fig 1: Spans get cut off by table overflow.图 1:跨度被表溢出切断。 Fig 2: Without overflow (intended overflow behaviour is this but with a scrollbar.图 2:没有溢出(预期的溢出行为是这样的,但带有滚动条。

在此处输入图像描述 在此处输入图像描述

HTML HTML

    <section class="variable-layout">
        <div class="variables">
            <table id="adminPasser" name="True">
                <tr>
                    <th>Variable Name</th>
                    <th>Value</th>
                    <th>Unit</th>
                    <th>Lock</th>
                </tr>
            <!-- Other rows inserted here -->
            </table>
        </div>
        <div class="var-actions">
            <span onclick="openPopup(0)">Add Variable</span>       
            <span id="apply" name="1">Apply Locks</span>                
        </div>
    </section>

CSS CSS

   .spreadsheet-layout {
       display: flex;
       flex-direction: row;
       height: 100%;
   }
   .variable-layout {
       height: 100%;
       display: flex;
       flex-direction: column;
       width: 20%;
       border-right: 2px solid #213B54;
       overflow: scroll;
   }
   .variables {
       border-top: 2px solid #213B54;
       width: 100%;
       height: auto;
   }
   .var-actions {
       display: flex;
       flex-direction: row;
       margin: 0px auto;
       font-family: Arial, sans-serif;
       font-size: 18px;
       color: #067A9F;
       padding-top: 1vw;
   }
   .var-actions span {
       padding-left: 1vw;
       padding-right: 1vw;
       cursor: pointer;
   }  

I was expecting that the entire flex container when set to overflow: scroll;我期待整个 flex 容器设置为溢出时:滚动; would scroll when there was an overflow caused by the table becoming too large, instead only the table scrolled when it was too large and the spans are hidden beneath the table with no option to scroll the entire container, only the table (which does not have overflow: scroll;).当表格变得太大而导致溢出时会滚动,而不是只有当表格太大并且跨度隐藏在表格下方时滚动,没有选项可以滚动整个容器,只有表格(没有溢出:滚动;)。

Try this:尝试这个:

Add a fixed height to your .variable-layout element and set it's scrol-y to scroll.为您的.variable-layout元素添加一个fixed height ,并将它的scrol-y设置为滚动。 Remove flex-direction and add flex-wrap to it.删除flex-direction并向其添加flex-wrap

 .spreadsheet-layout { display: flex; flex-direction: row; height: 500px; }.variable-layout { height: 200px; display: flex; width: 20%; border-right: 2px solid #213B54; overflow-y: scroll; flex-wrap: wrap; border-right: 2px solid #213B54; }.variables { border-top: 2px solid #213B54; width: 100%; height: auto; }.var-actions { display: flex; flex-direction: row; margin: 0px auto; font-family: Arial, sans-serif; font-size: 18px; color: #067A9F; padding-top: 1vw; height:300px; }.var-actions span { padding-left: 1vw; padding-right: 1vw; cursor: pointer; }
 <section class="variable-layout"> <div class="variables"> <table id="adminPasser" name="True"> <tr> <th>Variable Name</th> <th>Value</th> <th>Unit</th> <th>Lock</th> </tr> <!-- Other rows inserted here --> </table> </div> <div class="var-actions"> <span onclick="openPopup(0)">Add Variable</span> <span id="apply" name="1">Apply Locks</span> </div> </section>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM