How would one go about using CSS properties to allow a div
with nested div
s, which have absolute position defined, to be able to scroll once the defined position of those div
s goes outside of their parent div
?
I've stripped down my project to (hopefully) contain only what you need below, and I recognize that there are much cleaner ways to do this with the example that I'm presenting here, but figure it's worth asking because someone may have insight that I (and others) can learn from.
In my example, there are div
'boxes' (they have class=stuffbox
) being placed inside of a div
(has class=innerstuffcols
) and they overflow the vertical bounds of their parent div
.
#mainHeader {
background-color: #999999;
color: #ffffff;
position: absolute;
width: 100%;
height: 5%;
left: 0;
top: 0;
}
#mainPlace {
position:absolute;
width:100%;
height:95%;
left:0;
top:5%;
overflow:hidden;
}
#mainTable {
position:absolute;
left:0;
height:100%;
width: 85%;
overflow:hidden;
}
#mainMenu {
position:absolute;
left:85%;
right:0;
height:100%;
}
#tablebody {
height: 100%;
width: 100%;
}
th.tableheaders {
border:1px solid black;
height: 5%
}
td.someCols {
border:1px solid black;
}
table, th, td {
border-collapse: collapse;
}
div.innerstuffCols {
height: 100%;
width:100%;
overflow-y: auto;
overflow-x: hidden;
}
div.stuffbox {
height:200px;
position:absolute;
width:200px;
left:5px;
text-align: center;
background-color: #f1f1f1;
}
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>stuff</title>
<link rel="stylesheet" href="st.css">
</head>
<body>
<div id="mainHeader">
<p align="center"> random header here </p>
</div>
<div id="mainPlace">
<div id="mainTable">
<table style='width:100%;height:100%;position:absolute;top:0;bottom:0;left:0;border:1px solid black'>
<tr id='tableheader'>
<th class='tableheaders'>header 1</th>
<th class='tableheaders'>header 2</th>
</tr>
<tr id='tablebody'>
<td class='someCols'>
<div class='innerstuffCols'>
<div class='stuffbox' style='top:55px;'> stuff 1 </div>
<div class='stuffbox' style='top:265px;'> stuff 2 </div>
<div class='stuffbox' style='top:475px;'> stuff 3 </div>
<div class='stuffbox' style='top:685px;'> stuff 4 </div>
<div class='stuffbox' style='top:895px;'> stuff 5 </div>
<div class='stuffbox' style='top:1105px;'> stuff 6 </div>
</div>
</td>
<td class='someCols'>
<div class='innerstuffCols'>
some other stuff
</div>
</td>
</tr>
</table>
</div>
<div id="mainMenu">
<p> some stuff here </p>
</div>
</div>
</body>
</html>
As mentioned, I know that within the scope of only what is presented in my example, there are better ways to do this (making position something other than absolute, etc..) but for various reasons related to the much larger project (and at this point - academic curiosity) I'd prefer to see an explanation of how to get the example above working while keeping those div
s with their absolute position.
Apologies if the wording of the question is poor (let me know and I'll take another shot at it), but hopefully the example makes my intention clear.
Thanks in advance.