溢出-y 不适用于 fr

克里斯蒂安S9

我有下一个 html 结构:

<div id="container">
  <header></header>
  <div id="content">
     <div class="something"></div>
     <div class="lateralInfo">
        <div class="menu"></div>
        <div class="data">
             // A lot of data 
        </div>          
     </div>      
  </div>
  <footer></footer>
</div>

并使用下一个 css 样式:

*{
    margin: 0;
    padding: 0;
    border:0;
    box-sizing: border-box;
}

 #container{
    position: absolute;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-rows: 50px 1fr 10px;
    align-items:stretch;
    justify-items:stretch;
}
#content{
    display: grid;
    grid-template-columns: 1fr 300px;
    background-color:rgb(128, 126, 126);
}
.something{
    position: relative;
    overflow-y:hidden;
    overflow-x:hidden;
    padding:10px;
    margin:30px 0px;
} 
.lateralInfo{
    background-color:#eaeaea;
    box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.5);
    position: relative;
    height: 100%;
    align-content:flex-start;
    display:grid;
    grid-template-rows: auto 1fr;
}
  .data{
     padding:10px;
     display:grid;
     grid-gap:10px;
     align-content: flex-start;
     overflow-y: scroll;
}

这给了我下一个输出: 在此处输入图片说明


当我插入很多divsin 时.data问题就出现,我HERE在图像中了。

.data{
  overflow-y: scroll;
}

overflow-y不管用。我检查了一些帖子,他们说它需要height在父级指定才能工作but

fr在所有父母中使用.data什么意味着他们需要使用所有可用空间,但不能更多。所以高度是指定的。那为什么不工作呢?


实际上我正在使用:

var contentHeight = $("#content").innerHeight();
$(".lateralInfo").css("height", contentHeight);  

设置的高度时,该网站的负载调整到每个屏幕,但是这是fr应该在CSS做。

So why is this happening since there is a fr height on all parents? And how to solve this with only css??

JSFiddle here

Timo

The CSS solution by Takit Isy will also scroll the div class="menu".

I think when you want to solve that problem, you have to change the html code a little bit.

Starting from your original code, wrap a new div style="position:relative" around your div class="data" and add this to the CSS of .data:

position:absolute;
height:100%;
width:100%;

Explanation:

Because of fr the last child node of lateralInfo will get some sort of min-height. But it won't get a max-height and you can't assign that manually, because it would be a formular. That's why your old solution not worked.

因此必须解决两个问题:不要让最后一个子元素lateralInfo变大,并为可滚动元素提供某种最大高度。环绕新 divdiv class="data"并给出div class="data" position:absolute解决第一个问题(因为新 div 不会随着它的绝对定位内容而增长)。第二个问题由height:100%(这是可行的,因为我们有具有所需高度的新父元素)解决了。

完整代码:

<div id="container">
  <header></header>
  <div id="content">
     <div class="something"></div>
     <div class="lateralInfo">
        <div class="menu">menu doesn't scroll away</div>
        <div style="position:relative">
           <div class="data">
              // A lot of data 
           </div>          
        </div>
     </div>      
  </div>
  <footer></footer>
</div>

CSS:

*{
    margin: 0;
    padding: 0;
    border:0;
    box-sizing: border-box;
}

 #container{
    position: absolute;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-rows: 50px 1fr 10px;
    align-items:stretch;
    justify-items:stretch;
}
#content{
    display: grid;
    grid-template-columns: 1fr 300px;
    background-color:rgb(128, 126, 126);
}
.something{
    position: relative;
    overflow-y:hidden;
    overflow-x:hidden;
    padding:10px;
    margin:30px 0px;
} 
.lateralInfo{
    background-color:#eaeaea;
    box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.5);
    position: relative;
    height: 100%;
    align-content:flex-start;
    display:grid;
    grid-template-rows: auto 1fr;
}
.data{
     position:absolute;
     height:100%;
     width:100%;
     padding:10px;
     display:grid;
     grid-gap:10px;
     align-content: flex-start;
     overflow-y: scroll;
}

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

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

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

clearfix不适用于溢出:自动

来自分类Dev

CSS溢出不适用于转换

来自分类Dev

对角溢出滚动不适用于Chrome和Opera

来自分类Dev

溢出:滚动不适用于弹性项目

来自分类Dev

溢出-不适用于ng-repeat

来自分类Dev

溢出隐藏不适用于 Safari 中的绝对元素

来自分类Dev

隐藏溢出不适用于 flexbox 和 margin auto

来自分类Dev

Flutter Text 溢出不适用于第二行

来自分类Dev

固定底部不适用于有溢出的父级

来自分类Dev

溢出:隐藏不适用于左侧的.animate(),但适用于右侧?

来自分类Dev

是什么使此代码适用于 Y 轴而不适用于 X 轴?

来自分类Dev

滚动不适用于已将溢出属性设置为滚动的div

来自分类Dev

文本溢出不适用于嵌入式块元素

来自分类Dev

溢出-x不适用于包装在td中的内容

来自分类Dev

溢出隐藏不适用于“垂直对齐的底部” - 绝对定位的外部 div 中的 div

来自分类Dev

为什么文本溢出:省略号不适用于 Firefox 中的 display: inline-flex?

来自分类Dev

MATLAB imagesc命令不适用于非均匀间隔的y轴值

来自分类Dev

使用货币值时,SQLite ROUND(X,Y)不适用于尾随零

来自分类Dev

重命名'y / AZ / az /'*不适用于Linux的Windows子系统(WSL)

来自分类Dev

未提供 y_range.start 时,散景悬停不适用于零值

来自分类Dev

溢出-x也隐藏了溢出-y

来自分类Dev

适用于固定Div的iOS 7溢出滚动

来自分类Dev

溢出-y:滚动; 或溢出-y:auto; 没用

来自分类Dev

触摸板不适用于带有 Lenovo Legion Y730 的 Ubuntu 16.04 LTS

来自分类Dev

溢出y不会滚动

来自分类Dev

用于排序数组的QuickSort堆栈溢出(适用于其他数据集)

来自分类Dev

Chart.js两个y轴折线图工具提示值不适用于第二个y轴

来自分类Dev

隐藏在底部的溢出仅适用于复杂形状的图像

来自分类Dev

CSS溢出-y不滚动

Related 相关文章

  1. 1

    clearfix不适用于溢出:自动

  2. 2

    CSS溢出不适用于转换

  3. 3

    对角溢出滚动不适用于Chrome和Opera

  4. 4

    溢出:滚动不适用于弹性项目

  5. 5

    溢出-不适用于ng-repeat

  6. 6

    溢出隐藏不适用于 Safari 中的绝对元素

  7. 7

    隐藏溢出不适用于 flexbox 和 margin auto

  8. 8

    Flutter Text 溢出不适用于第二行

  9. 9

    固定底部不适用于有溢出的父级

  10. 10

    溢出:隐藏不适用于左侧的.animate(),但适用于右侧?

  11. 11

    是什么使此代码适用于 Y 轴而不适用于 X 轴?

  12. 12

    滚动不适用于已将溢出属性设置为滚动的div

  13. 13

    文本溢出不适用于嵌入式块元素

  14. 14

    溢出-x不适用于包装在td中的内容

  15. 15

    溢出隐藏不适用于“垂直对齐的底部” - 绝对定位的外部 div 中的 div

  16. 16

    为什么文本溢出:省略号不适用于 Firefox 中的 display: inline-flex?

  17. 17

    MATLAB imagesc命令不适用于非均匀间隔的y轴值

  18. 18

    使用货币值时,SQLite ROUND(X,Y)不适用于尾随零

  19. 19

    重命名'y / AZ / az /'*不适用于Linux的Windows子系统(WSL)

  20. 20

    未提供 y_range.start 时,散景悬停不适用于零值

  21. 21

    溢出-x也隐藏了溢出-y

  22. 22

    适用于固定Div的iOS 7溢出滚动

  23. 23

    溢出-y:滚动; 或溢出-y:auto; 没用

  24. 24

    触摸板不适用于带有 Lenovo Legion Y730 的 Ubuntu 16.04 LTS

  25. 25

    溢出y不会滚动

  26. 26

    用于排序数组的QuickSort堆栈溢出(适用于其他数据集)

  27. 27

    Chart.js两个y轴折线图工具提示值不适用于第二个y轴

  28. 28

    隐藏在底部的溢出仅适用于复杂形状的图像

  29. 29

    CSS溢出-y不滚动

热门标签

归档