In the following HTML setup:
<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>
And with the corresponding CSS styles applied:
*{
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;
}
The result is as shown in this https://i.sstatic.net/oIHga.png.
An issue arises when numerous divs
are placed within .data
, indicated by "HERE" in the image.
.data{
overflow-y: scroll;
}
The overflow-y
property appears to be ineffective.
Despite specifying a height
for the parent element according to some sources,
I have utilized fr
units in all parent elements of .data
, which should allocate exactly the necessary space. So, why is it not functioning as anticipated?
Currently, my approach involves:
var contentHeight = $("#content").innerHeight();
$(".lateralInfo").css("height", contentHeight);
To establish a suitable height when the page loads in response to various screen sizes. However, this strategy contradicts the intent of using fr
units in CSS.
Hence, why does this discrepancy occur even though
fr
units are specified for all parent elements? Is there a CSS-only solution available?
Explore the code on JSFiddle here