Issue
I am attempting to replicate the layout depicted in the image below. The black area represents the body with id="library"
, the grey div is id="body"
(which is not visible due to lack of margins for inner divs), the light blue div is id="sideBar"
, the red div is id="content"
, the blue div is id="navBar"
, and the green div is id="contentWindow"
.
Image:
https://i.sstatic.net/A3EBU.png
I am facing difficulties in containing the green div within the red div (its parent). I would like to adjust only the green div's margins in relation to the red div without having to explicitly set the height. Here is my current implementation:
My goal is to ensure that all divs adjust to the screen width and height so that everything remains visible at all times, even on smaller browser windows.
I have reviewed several links but have not found a solution:
Resizable DIV inside DIV 100% height with margin around not working well! Some help please?
How to push a div inside this div structure?
Parent div expand with children Div
The code can be seen in the fiddle above, but I have also provided it here:
body.library,
html {
background: black;
height: 100%;
margin: 0;
padding: 0;
border: 0 none;
}
div#body {
/*display:block;*/
background: #E6E6E6;
max-width: 400px;
display: block;
height: 90%;
margin-top: 20px;
margin-bottom: 20px;
margin-left: auto;
margin-right: auto;
}
div#sidebar {
/*display:block;
position:relative;*/
background: #94DBFF;
float: left;
width: 50px;
height: 100%;
}
div#content {
/*display:block;
position:relative;*/
background: #FF0000;
min-width: 70px;
margin-right: 0px;
margin-left: 50px;
margin-top: 0px;
margin-bottom: 0px;
height: 100%;
}
div#contentWindow {
display: block;
position: relative;
height: auto;
bottom: 0;
top: 0;
left: 0;
right: 0;
margin-top: 20px;
margin-bottom: 20px;
margin-right: 80px;
margin-left: 80px;
background-color: green;
height: 100%;
overflow: auto;
}
div#navBar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
text-align: center;
}
<body class="library">
<div id=body>
<div id="sidebar">
<p>Hey</p>
<p>Hey</p>
<p>Hey</p>
<p>Hey</p>
</div>
<div id="content">
<div id="navBar">
<p>Hello</p>
</div>
<div id="contentWindow">
<p>Hey</p>
</div>
</div>
</div>
</body>