I have three divs (left, mid and right) and these divs don't have an exact height, because it depends on how many rows text are inside the div.
Now I want vertical lines (which seperate the three divs) through the whole height of the users monitor, no matter how high the divs are.
How can I do this? Because , as you can see in the css-code, border-right/border-left don't work for me.
Intention
HTML
<div class="content">
<div class="content_left"></div>
<div class="content_mid"></div>
<div class="content_right"></div>
</div>
CSS
.content {
line-height: 1.1;
background-color: #FFF;
color: #000;
position: absolute;
top: 36px; /* because there is a top-menu which is 36px high */
left: 70px; /* because there is a side-menu which is 70px wide */
right: 0px;
bottom: 0px;
overflow-x: hidden;
overflow-y: auto;
}
.content_left {
position: absolute;
width: 22.5%;
left: 0px;
top: 0px;
border-right: 1px solid #ccc;
padding: 10px;
overflow-x: hidden;
overflow-y:hidden;
}
.content_mid {
position: relative;
width: 50%;
top: 10px;
left: 25%;
float: left;
padding-left: 10px;
}
.content_right {
position: absolute;
width: 22.5%;
right: 0px;
top: 0px;
border-left: 1px solid #ccc;
padding: 10px;
overflow-x: hidden;
overflow-y: hidden;
}
Edit 1: I would like to have these seperate-lines 1px wide and I cannot set the height of content_left, content_mid, content_right to 100% because I have resizeable boxes in these divs.
I think this does what you want.
JSFiddle example
The HTML structure is a bit more complicated than yours:
<div class="menu-top">Menu top</div>
<div class="wrapper">
<div class="menu-left">Menu left</div>
<div class="content">
<div class="column">
<div class="column-content">
<h1>Column 1</h1>
</div>
</div>
<div class="column">
<div class="column-content">
<h1>Column 2</h1>
</div>
</div>
<div class="column">
<div class="column-content">
<h1>Column 3</h1>
</div>
</div>
</div>
</div>
And here's the CSS:
body {
padding: 0;
margin: 0;
box-sizing: border-box;
height: 100%;
width: 100%;
}
.menu-top {
width: 100%;
height: 36px;
background-color: #3498DB;
}
.wrapper {
display: flex;
}
.menu-left {
height: calc(100vh - 36px);
width: 70px;
background-color: #59ABE3;
}
.content {
width: calc(100vw - 70px);
height: calc(100vh - 36px);
background-color: #E4F1FE;
display: flex;
}
.column {
flex: 33;
border-left: 1px solid hotpink;
}
.column:first-of-type {
border-left: none;
}
You can actually fake it using background-color for the parent.
/* Start Praveen's Reset for Fiddle ;) */
* {font-family: 'Segoe UI'; margin: 0; padding: 0; list-style: none; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;}
/* End Praveen's Reset for Fiddle ;) */
.parent {background-color: #f99; height: 100%; overflow: hidden; position: relative;}
.parent .col {float: left; background-color: #fff; height: 100%; margin: 0.5%; width: 32.25%; position: relative;}
<div class="parent">
<div class="col">
<p>I am one line!</p>
</div>
<div class="col">
<p>I am three lines!</p>
<p>I am three lines!</p>
<p>I am three lines!</p>
</div>
<div class="col">
<p>I am two lines!</p>
<p>I am two lines!</p>
</div>
</div>
Fiddle: http://output.jsbin.com/hefefawilu/1
Just Created a fiddle using your code.
See and let me know if this solves your issue.
http://jsfiddle.net/knxd0htm/
Add this part of code to make it work
**HTML:**
<div class="content">
<div class="content_left">a</div>
<div class="full-height one"></div>
<div class="content_mid">b</div>
<div class="full-height two"></div>
<div class="content_right">c</div>
</div>
**CSS**
/**** CODE ****/
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 0;
margin: 0;
}
.content {
height: calc(100%-36px);
min-height: calc(100%-36px);
}
.full-height {
position: absolute;
height: 100%;
border-left: 1px solid red;
}
.full-height.one {
left: 22.5%;
}
.full-height.two {
right: 22.5%;
}
/**** CODE ****/
You can achieve this without adding an extra HTML by using Pseudo selectors. I've also tidied up some of the code that works out widths :).
* {
box-sizing:border-box;
}
html, body {
height:100%;
width:100%;
}
body {
position:relative;
margin:0;
padding:0;
}
.content {
line-height: 1.1;
background-color: #FFF;
color: #000;
position: absolute;
top: 36px;
/* because there is a top-menu which is 36px high */
left: 70px;
/* because there is a side-menu which is 70px wide */
right: 0px;
bottom: 0px;
overflow-x: hidden;
overflow-y: auto;
}
.content_left {
position: absolute;
width: calc(25% - 35px);
left: 0px;
top: 0px;
padding: 10px;
overflow-x: hidden;
overflow-y: hidden;
}
.content_mid {
position: relative;
width: 50%;
top: 10px;
left: 25%;
float: left;
padding-left: 10px;
}
.content_right {
position: absolute;
width: calc(25% - 35px);
right: 0px;
top: 0px;
padding: 10px;
overflow-x: hidden;
overflow-y: hidden;
}
.content:before {
content: '';
border-left:1px solid #ccc;
width:0;
position:absolute;
top:0;
left:25%;
bottom:0;
}
.content:after {
content: '';
border-right:1px solid #ccc;
width:0;
position:absolute;
top:0;
right:25%;
bottom:0;
}
<div class="content">
<div class="content_left"></div>
<div class="content_mid"></div>
<div class="content_right"></div>
</div>
Related
I have been able to create a centered vertical line but it increases my webpage width off of my screen! I would like some insight on how I can create a centered vertical line down my page while keeping page width to fit my screen (so that there is no horizontal scroll bar).
When I have removed the line my page width is perfect therefore I do not think it is one of my divs causing the problem.
body {
background-color: lightblue
}
.vertical_line {
border-left: 6px solid black;
height: 500px;
position: relative;
left: 50%;
margin-left: auto;
z-index: -1;
}
.section-2 {
width: 100%;
height: 200px;
}
.section-3 {
position: relative;
top: 50;
width: 500px;
height: 60%;
padding: 20px;
margin-left: auto;
margin-right: auto;
background-color: green;
}
<section class="section-2">
<div class="topnav">
<a style="background-color:grey; width:100px">this is my nav bar</a>
</div>
<div class="vertical_line"></div>
</section>
<section class="section-3">
<div class="paragraph"></div>
</section>
<div class="vertical_line"></div>
Problem arises because you used position: relative; and shifted it 50% left, but it means element is still part of flow and shifting it pushes it past the edge of the screen. On the other hand position absolute removes it from the flow. But if you want to use position: relative; for some reason, then add overflow-x : hidden; in the body, it will work fine in your case. Also a good CSS reset always helps, so as you do not get unexpected scrollbars.
* {
padding: 0px;
margin: 0px;
}
body {
background-color: lightblue;
width: 100%;
min-height: 100vh;
}
.vertical_line {
border-left: 6px solid black;
height: 500px;
position: absolute;
left: 50%;
margin-left: auto;
z-index: -1;
}
.section-2 {
width: 100%;
height: 200px;
}
.section-3 {
position: relative;
top: 50;
width: 500px;
height: 60%;
padding: 20px;
margin-left: auto;
margin-right: auto;
background-color: green;
}
<html>
<section class="section-2">
<div class="topnav">
<a style="background-color:grey; width:100px">this is my nav bar</a>
</div>
<div class="vertical_line"></div>
</section>
<section class="section-3">
<div class="paragraph"></div>
</section>
<div class="vertical_line"></div>
</html>
With help of overflow-x: hidden; and position : relative; :
* {
padding: 0px;
margin: 0px;
}
body {
width: 100%;
min-height: 100vh;
overflow-x: hidden;
}
.vl {
border-left: 6px solid black;
height: 5000px;
position: relative;
left: 50%;
}
<html>
<body>
<h2>Vertical Line</h2>
<div class="vl"></div>
</body>
</html>
I want to create a layout like this-
Footer is sticky.
Below is the code I tried:
body {
position: relative;
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
user-select: none;
}
html,
body {
height: 100%;
margin: 0;
}
.container {
max-width: 1280px;
margin: 0 auto;
}
.page-wrap {
min-height: 100%;
margin-bottom: -45px;
background-color: #f2f2f2;
}
#header {
height: 80px;
width: 100%;
background-color: #fdbb30;
position: relative;
padding-bottom: 10px;
}
.adminpanelContainer {
background-color: white;
padding: 40px;
margin-top: 20px;
height: 100%;
}
#footer {
width: 100%;
background-color: #fff;
z-index: 1;
}
#footerwrapper {
height: 45px;
}
<body>
<div class="page-wrap">
<header id="header">
<div class="container"></div>
</header>
<div id="body">
<div class="container" style="height:100%;">
<div class="panelContainer"></div>
</div>
</div>
</div>
<footer id="footer">
<div class="container" id="footerwrapper"></div>
</footer>
</body>
I am giving height: 100% to .adminpanelContainer and its ancestors also but there is no effect on it.
I want the white area to expand across the whole web page irrespective of their height.
What changes I have to make to extend the div till bottom.
This will work for you:
I have just added ↓
#body .container{
height: calc(100vh - (90px + 45px));
}
the calculation is as follows:
height: calc(100ViewportHeight - (#header[height+padding-bottom]+ #footerwrapper[height]));
If you want to learn more about calc and vh, please click on them.
A working Sample from your snippet:
body {
position: relative;
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
user-select: none;
}
html,
body {
height: 100%;
margin: 0;
}
.container {
max-width: 1280px;
margin: 0 auto;
}
.page-wrap {
min-height: 100%;
margin-bottom: -45px;
background-color: #f2f2f2;
}
#header {
height: 80px;
width: 100%;
background-color: #fdbb30;
position: relative;
padding-bottom: 10px;
}
.adminpanelContainer {
background-color: white;
padding: 40px;
margin-top: 20px;
height: 100%;
}
#footer {
width: 100%;
background-color: #fff;
z-index: 1;
}
#footerwrapper {
height: 45px;
}
#body .container{
height: calc(100vh - (90px + 45px));
}
<body>
<div class="page-wrap">
<header id="header">
<div class="container">
</div>
</header>
<div id="body">
<div class="container" >
<div class="panelContainer">
</div>
</div>
</div>
</div>
<footer id="footer">
<div class="container" id="footerwrapper">
</div>
</footer>
</body>
Hope this was helpful for you.
Without adjusting any existing markup the intended behaviour can be achieved by declaring <percentage> height unit values for applicable nested elements as well.
Start by declaring a relative height (with percentage unit values)
for the element #body - account for the combined height of the
nested header & footer elements, e.g:
#body {
/* 100% height minus the sum of header & footer height */
height: calc(100% - 125px);
}
Next, declare height: 100% for any further nested elements that
are required to occupy the full available height of the viewport,
e.g:
.panelContainer {
height: 100%;
}
The code snippets below demonstrate this behaviour with both fixed and relative footer elements.
Fixed Footer:
body {
position: relative;
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
user-select: none;
}
html,
body {
height: 100%;
margin: 0;
}
.container {
max-width: 1280px;
margin: 0 auto;
text-align: center;
}
.page-wrap { /* adjusted */
height: 100%;
background-color: #f2f2f2;
}
#header {
height: 80px;
width: 100%;
background-color: #fdbb30;
position: relative;
padding-bottom: 10px;
}
.adminpanelContainer {
background-color: white;
padding: 40px;
margin-top: 20px;
height: 100%;
}
#footer {
width: 100%;
background-color: #fff;
z-index: 1;
/* additional */
position: fixed;
bottom: 0;
}
#footerwrapper {
height: 45px;
}
/* Additional */
* {
box-sizing: border-box;
}
#body {
height: calc(100% - 125px); /* 100% height minus the sum of header & footer height */
}
.panelContainer {
height: 100%;
/* following styles added just for the sake of demonstration */
background: white;
border: 1px solid #d6d6d6;
box-sizing: border-box;
max-width: 80%;
margin: auto;
}
.panelContainer .inner {
position: relative;
height: 100%;
}
.panelContainer .inner span {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 20px;
margin: auto;
}
<body>
<div class="page-wrap">
<header id="header">
<div class="container">
<span>height: 80px</span>
</div>
</header>
<div id="body">
<div class="container" style="height:100%;">
<div class="panelContainer">
<div class="inner"><span>relative height declared with <code>percentage</code> values</span></div>
</div>
</div>
</div>
</div>
<footer id="footer">
<div class="container" id="footerwrapper">
<div class="container">
<span>height: 45px</span>
</div>
</div>
</footer>
</body>
Relative Footer:
body {
position: relative;
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
user-select: none;
}
html,
body {
height: 100%;
margin: 0;
}
.container {
max-width: 1280px;
margin: 0 auto;
text-align: center;
}
.page-wrap { /* adjusted */
height: 100%;
background-color: #f2f2f2;
}
#header {
height: 80px;
width: 100%;
background-color: #fdbb30;
position: relative;
padding-bottom: 10px;
}
.adminpanelContainer {
background-color: white;
padding: 40px;
margin-top: 20px;
height: 100%;
}
#footer {
width: 100%;
background-color: #fff;
z-index: 1;
/* additional */
position: relative;
bottom: 0;
}
#footerwrapper {
height: 45px;
}
/* Additional */
* {
box-sizing: border-box;
}
body {
padding-bottom: 45px;
}
#body {
height: calc(100% - 80px); /* 100% height minus the height of the header */
}
.panelContainer {
height: 100%;
/* following styles added just for the sake of demonstration */
background: white;
border: 1px solid #d6d6d6;
box-sizing: border-box;
max-width: 80%;
margin: auto;
}
.panelContainer .inner {
position: relative;
height: 100%;
}
.panelContainer .inner span {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 20px;
margin: auto;
}
<body>
<div class="page-wrap">
<header id="header">
<div class="container">
<span>height: 80px</span>
</div>
</header>
<div id="body">
<div class="container" style="height:100%;">
<div class="panelContainer">
<div class="inner"><span>relative height declared with <code>percentage</code> values</span></div>
</div>
</div>
</div>
</div>
<footer id="footer">
<div class="container" id="footerwrapper">
<div class="container">
<span>height: 45px</span>
</div>
</div>
</footer>
</body>
Practical Interactive CodePen Demonstrations:
Here you can observe practical demonstrations, for fixed and relative footers, which allow content to be added or removed dynamically. In addition, these demonstrations also account for dynamic footer heights.
Keeping a Fixed Footer at the bottom of page (Dynamic Footer Height)
Keeping a Relative Footer at the bottom of page (Dynamic Footer
Height)
Please note
the vertical scrollbars should show up when needed
left columns fits to width
right column takes the rest of the space
Here is one approach that uses CSS only.
The HTML looks like:
<div id="pageWrapper">
<header>Header</header>
<div id="contentWrapper">
<div class="table-wrap">
<div class="cell col1">
<div class="content">Column 1: Shrink-to-Fit Width</div>
</div>
<div class="cell col2">
<div class="content">Column 2: Variable Width</div>
</div>
</div>
</div>
<div id="footerWrapper">Footer</div>
</div>
and the CSS:
html, body {
height: 100%;
margin: 0;
}
body {
background-color: #E3E3E3;
}
#pageWrapper {
margin: 0 auto;
position: relative;
width: 90%; /*set to 100% or smaller or fixed width... */
height: 100%;
}
header {
display:block;
width: 100%;
height: 100px;
background: yellow;
}
#contentWrapper {
width: 100%;
position: absolute;
top: 100px;
bottom: 100px;
left: 0;
background: beige;
}
#footerWrapper {
width: 100%;
position: absolute;
height: 100px;
bottom: 0px;
left: 0;
background: gray;
}
.table-wrap {
width: 100%;
height: 100%;
}
.table-wrap .cell {
height: 100%;
}
.table-wrap .col1 {
float: left;
border: 1px dotted blue;
max-width: 80%; /* This is critical or else Column 2 can disappear */
}
.table-wrap .col1 .content {
height: inherit;
display: inline-block;
overflow-y: auto;
}
.table-wrap .col2 {
}
.table-wrap .col2 .content {
height: inherit;
overflow-y: auto;
}
See demo at: http://jsfiddle.net/audetwebdesign/kbAwf/
How This Works
Use absolute positioning to place the header, main content area and footer within the view port area.
Within the content area (#contentWrapper), the .table-wrap container has two cells, one which is floated left (column 1). This allows column 2 to fill the rest of the width.
To get the shrink-to-fit width for column 1, set display: inline-block to the inner .content container.
Finally, use overflow-y: auto for the scroll bars. (You can also use the scroll value.)
You need to set a maximum width to .col1 so that .col2 does not get pushed out of the view port. I set it to 80% but you can adjust it.
Also, note that an inline-block will expand as much as possible to flow its content, which is why you need to constrain it.
You man want to set a minimum width on #pageWrapper to prevent the layout from shrinking to something that is less than useful.
Like this
DEMO1
DEMO1 CSS
html, body {
height:100%;
}
header{
width: 100%;
background: yellow;
position: fixed;
top: 0;
height: 60px !important;
opacity:.8;
}
.content {
position:relative;
height: 100%;
/*width:600px; Sizing - any length */
padding:60px 0 30px 0; /* Header height and footer height */
margin:0 auto 0 auto; /* Center content */
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
-o-box-sizing:border-box;
-ms-box-sizing:border-box;
box-sizing:border-box;
}
.sidebar1, .sidebar2 {
background: red;
top:60px;
bottom:30px;
width: 70%;
position:absolute;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
-o-box-sizing:border-box;
-ms-box-sizing:border-box;
box-sizing:border-box;
overflow-y:scroll;
}
.sidebar1 {
left:0;
width:30%;
}
.sidebar2 {
right: 0;
}
#scrollable2 {
background:green;
height: 100%;
min-width: 300px;
margin-left: 100px;
margin-right: 100px;
overflow:auto;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
-o-box-sizing:border-box;
-ms-box-sizing:border-box;
box-sizing:border-box;
}
footer {
width: 100%;
background: yellow;
position: fixed;
bottom: 0;
height: 30px;
}
DEMO2
HTML
<div class="main">
<div class="header"></div>
<div class="mid">
<div class="left"></div>
<div class="right"></div>
</div>
<div class="footer"></div>
</div>
CSS
body, html {
width: 100%;
height: 100%;
background-color: black;
padding: 0;
margin: 0;
}
.main {
background-color: white;
top: 4px;
left: 4px;
right: 4px;
bottom: 4px;
}
.main, .header, .left, .right, .mid, .footer {
position: absolute;
}
.header {
height: 100px;
top: 0px;
left: 0px;
right: 0px;
border-bottom: 4px solid black;
}
.mid {
top: 104px;
left: 0px;
right: 0px;
bottom: 14px;
}
.left {
overflow-y:auto;
width: 100px;
top: 0px;
bottom: 0px;
}
.right {
overflow-y:auto;
top: 0px;
bottom: 0px;
left: 100px;
right: 0px;
border-left: 4px solid black;
}
.footer {
left: 0px;
right: 0px;
bottom: 0px;
height: 10px;
border-top: 4px solid black;
}
Working Fiddle (as shown in your post)
Hi I would like center correctly my content inside the container but I don't know how to do this. I have tried text-align : center.
How can I do this ?
HTML
<div id="Contacts" data-bind="foreach: viewModel.contacts()">
<div class="title">
<div class="container">
<small> <span class="red"> NEW CONTACT</span> </small>
<br>
<br>
</div>
</div>
</div>
CSS
.container {
width: 940px;
margin-left: auto;
margin-right: auto;
zoom: 1;
}
.title {
width: 540px;
height : 30px;
margin-bottom: 10px;
background-color: #F9F7F7;
border: 1px solid #e4e4e4;
position: absolute;
}
no centering
Centered version (approximative) what I would like :
Add line-height:30px; to .title class.
.container {
width: 940px;
margin-left: auto;
margin-right: auto;
zoom: 1;
}
.title {
width: 540px;
height : 30px;
line-height : 30px;
margin-bottom: 10px;
background-color: #F9F7F7;
border: 1px solid #e4e4e4;
position: absolute;
}
Jsfiddle: http://jsfiddle.net//vU73t/
.centerMe {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
/* dimensions */
}
Here is corrected css and HTML with Fiddle link.
HTML
<div id="Contacts">
<div class="container">
<div class="title">
Demo Text goes here <br>
</div>
</div>
</div>
CSS
*{
padding:0;
margin:0;
}
.container {
width: 940px;
margin:0 auto;
zoom: 1;
background-color:#ffb7b7;
padding:20px;
text-align:center;
}
.title {
width:540px;
height:30px;
margin-bottom: 10px;
background-color: #F9F7F7;
border: 1px solid #e4e4e4;
margin:0 auto;
/*position: absolute;*/
}
+-------------------+
| Top (fixed) |
+-------------------+
| |
| |
| Middle (fill) |
| |
| |
+-------------------+
| Bottom (fixed) |
+-------------------+
The top and bottom are fixed divs. They are positioned on the top and bottom of browser window. I want the middle part to fill the rest of the window between top and bottom divs.
If it's content is more than its height then i can use scrollbars. But its size should not exceed the window.
My CSS and HTML:
html, body, #main
{
height: 100%;
}
#content
{
background: #F63;
width: 100%;
overflow: auto;
height: 100%;
margin-bottom: -100px;
}
#footer
{
position: fixed;
display: block;
height: 100px;
background: #abcdef;
width: 100%;
}
<div id="main">
<div id="content">xyz</div>
<div id="footer">abc</div>
</div>
From this, the Footer shows in the bottom but, the Content div still fills the whole window which should have been [window-footer] height.
Position the middle div using absolute positioning without specifying height. It does not get much simpler than this:
#header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 100px;
background-color: #abcdef;
}
#footer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 100px;
background-color: #abcdef;
}
#content {
position: fixed;
top: 100px;
bottom: 100px;
left: 0;
right: 0;
background-color: #F63;
overflow: auto;
}
<div id="header"></div>
<div id="content"></div>
<div id="footer"></div>
Use "Full page" option to view the snippet properly.
If you don't know the header or footer sizes and you can use CSS3 then i would suggest to use flexbox layouting.
Example below (or check fiddle)
HTML:
<div class="container">
<div class="header">header</div>
<div class="content">content</div>
<div class="footer">bottom</div>
</div>
CSS:
.container {
display: flex;
flex-direction: column;
width: 100%;
height: 400px;
}
.header {
flex-grow: 0;
background-color: red;
}
.content {
flex-grow: 1;
background-color: green;
}
.footer {
flex-grow: 0;
background-color: blue;
}
html
<div id="main">
<div id="header"> Header Content</div>
<div id="content">
<ul><li>Hello World!!! </li>
<li>Hello World!!! </li>
<li>Hello World!!! </li>
<li>Hello World!!! </li>
<li>Hello World!!! </li>
</ul>
</div>
<div id="footer">I am Footer
</div>
css
body { margin: 0;}
#main{
position: absolute;
width: 100%;
top: 0;
bottom: 0;}
#header
{
position: absolute;
height: 41px;
top: 0;
left: 0;
right: 0;
text-align:center;
display:block;
background: blue;
}
#content
{
position: absolute;
top: 41px;
bottom: 0;
left: 0;
right: 0;
overflow:scroll;
}
#footer
{
position: absolute;
height: 41px;
bottom: 0;
left: 0;
right: 0;
text-align:center;
display:block;
background: blue;
}
li{
text-decoration: none;
display: block;
height: 20px;
width: 100%;
padding: 20px;
}
JSFIDDLE Demo
I think this is what u want...
JSBin: http://jsbin.com/ebilag/1/
CSS:
html, body {
top: 0;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.top {
position: fixed;
top: 0;
width: 100%;
height: 100px;
background: yellow;
}
.bottom {
position: fixed;
bottom: 0;
width: 100%;
height: 100px;
background: grey;
}
.middle {
padding-top: 100px;
padding-bottom: 100px
}
HTML:
<div class="container">
<div class="top">Top</div>
<div class="middle">Middle</div>
<div class="bottom">Bottom</div>
</div>
If you know the height of the header and the footer...
then you could do this easily with the box-sizing property.
Like so:
FIDDLE1 FIDDLE2
.container
{
height: 100%;
background: pink;
margin: -64px 0;
padding: 64px 0;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.content {
overflow:auto;
height:100%;
}
header
{
height: 64px;
background: purple;
position: relative;
z-index:1;
}
footer
{
height: 64px;
background: gray;
position: relative;
z-index:1;
}
The solution with top and bottom padding is ok but I would suggest a different approach where the main frame is designed as table. This is more flexible and you can hide head or foot without changing the css.
STYLUS (CSS):
html,
body
height: 100%
.container
display: table
height: 100%
.head,
.foot,
.content
display: table-row
box-sizing: border-box
.head,
.foot
height: 70px
background: #ff0000
.content
overflow: auto
.scroll
height: 100%
overflow: auto
box-sizing: border-box
HTML:
<div class="container">
<div class="head">...</div>
<div class="content">
<div class="scroll">...</div>
</div>
<div class="foot">...</div>
</div>
HTML:
<div id="main">
<div id="header">I am Header
</div>
<div id="content">I am the Content
</div>
<div id="footer">I am Footer
</div>
</div>
CSS:
#main{width:100%;height:100%;}
#header
{
position:relative;
text-align:center;
display:block;
background:#abcdef;
height:40px;
width:100%;
}
#content
{
background: #F63;
width:100%;
text-align:center;
height:auto;
min-height:400px;
}
#footer
{
position:relative;
text-align:center;
display:block;
background:#abcdef;
height:40px;
width:100%;
}
DEMO
In my opinion you should use js/jquery to change the #content height during page load.
This should be something like this (I haven't tested code below, so change it as you need):
$().ready(function(){
var fullHeight= function(){
var h=$(window).height()-100; //100 is a footer height
$('#content').css('min-height',h+'px');
};
$(window).resize(fullHeight);
fullHeight();
});
Please try this:
HTML
<div id="header">
header
</div>
<div id="content">
main content
</div>
<div id="footer">
footer
</div>
CSS
html,body{
marign: 0;
padding: 0;
height: 100%;
}
#header {
height: 100px;
position: fixed;
top: 0;
left:0;
right: 0;
background: orange;
}
#footer {
height: 100px;
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: green;
}
#content {
padding-top: 100px;
padding-bottom: 100px;
height: -webkit-calc(100% - 200px);
height: -moz-calc(100% - 200px);
height: -ms-calc(100% - 200px);
height; -o-calc(100% - 200px);
height: calc(100% - 200px);
background: #ccc;
}
please view the demo.