Fixed header, fixed footer dynamic content - html

I'm struggling with my dynamic content. So let me explain in a picture:
So my html looks like:
<div id="header"> ... </div>
<div id="container">
<div class="block"> ... </div>
<div class="block"> ... </div>
<div class="block"> ... </div>
<div class="block"> ... </div>
</div>
<div id="footer"> ... </div>
My question: How can I get my container be fluid and the header and footer be fixed? The blocks in the container are set on 50% height and width, so only the container has to be the 100% height (- the fixed header and footer).

You can do this with box-sizing property.
Like so:
FIDDLE
(the example I use here assumes a header of 64px height and footer of 30px height)
Markup
<header>header</header>
<div class="container">
<div id="content">
<div class="block">block1</div><!--
--><div class="block">block2</div><!--
--><div class="block">block3</div><!--
--><div class="block">block4</div>
</div>
</div>
<footer>footer</footer>
CSS
html,body
{
height: 100%;
}
header,footer,div
{
width: 100%;
}
.container
{
height: 100%;
background: pink;
margin: -64px 0 -30px;
padding: 64px 0 30px;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#content {
overflow:auto;
height:100%;
}
.block
{
width: 50%;
height: 50%;
display: inline-block;
border: 1px solid yellow;
-moz-box-sizing: border-box;
box-sizing: border-box;
text-align: center;
}
header
{
height: 64px;
background: purple;
position: relative;
z-index:1;
}
footer
{
height: 30px;
background: gray;
position: relative;
z-index:1;
}

Like this
working demo
css
*{
margin:0;
padding:0;
}
#header{
height:100px;
background-color:red;
position:fixed;
top:0;
width:100%;
}
#footer{
height:100px;
background-color:green;
position:fixed;
bottom:0;
width:100%;
}
#container{
background-color:#F7F7F7;
width:100%;
top:100px;
position:relative;
}
.block{
width:50%;
background-color:gray;
float:left;
}

Use float to make it fluid desgins.Be Caution about width part when border or padding is added. Because those are calculated with width. As Danield mentioned you can use Box sizing
Obviously Measurements should be in percentage to make it responsive Or alternatively you can write media queries.

You tagged your question with twitter-bootstrap. Here is a more Bootstrap friendly approach:
Demo: http://bootply.com/render/88297
Code: http://bootply.com/88297
This uses a somewhat standard BS header/nav and fixed footer. Then the center container uses table,table-row and table-cell to size the center boxes accordingly at 50/50.
.center-container {
height:100%;
display: table;
width:100%;
margin:0;
}
.center-row {
height:50%;
width:100%;
display: table-row;
}
.center-row > div {
height:100%;
width:50%;
display: table-cell;
border:1px solid #eee
}

Related

How to put a footer on bottom using css?

I've a simple web page that contains a <div> on background (a green rectangle on background) and a second <div> that is the "body" it contains paragraphs, table etc
And on bottom I need to to put a simple footer containing juste copyrights and some socials networks buttons. The problem is : the footer is not on bottom, there is a space under the footer, how to avoid this please ?
See my simple code please
On jsfiddle is better (to see the space under the footer) see here please
.bg-green{
width:100%;
height:100px;
background-color:green;
}
.content{
width:80%;
height:300px;
margin:-50px auto;
background-color:gold;
text-align:center;
}
footer{
width:100%;
height:65px;
background-color:red;
opacity:0.5;
}
<div class="bg-green">
</div>
<div class="content">
this is the "body" of my page (kind of a wrapper) it needs to be like this (with negative margin top)
</div>
<footer>this is the footer</footer>
You forgot to remove default margin of body.
Set in css:
body {
margin: 0;
}
Fiddle
body {
margin: 0;
}
.bg-green{
width:100%;
height:100px;
background-color:green;
}
.content{
width:80%;
height:300px;
margin: -50px auto;
background-color:gold;
text-align:center;
}
footer{
width:100%;
height:65px;
background-color:red;
opacity:0.5;
}
<div class="bg-green">
</div>
<div class="content">
this is the "body" of my page (kind of a wrapper) it needs to be like this (with negative margin top)
</div>
<footer>this is the footer</footer>
For best practice always set body and html 0 margin and 0 padding.
body,html{
margin:0;
padding:0;
}
Add this to .footer
margin-top:50px;
Perhaps you want to stick your footer to the bottom?
Clear the paddings and margins by:
html, body {
padding:0;
margin:0;
}
then
footer{
width:100%;
height:65px;
background-color:red;
opacity:0.5;
position:absolute;
bottom:0;
}
Working fiddle
Set the min height of body to 100% and set position to absolute.
.bg-green{
width:100%;
height:100px;
background-color:green;
}
.content{
width:80%;
height:300px;
margin:-50px auto;
background-color:gold;
text-align:center;
}
html, body{
padding: 0;
margin: 0;
}
html{
height: 100%;
}
body{
min-height: 100%;
}
footer{
width:100%;
height:65px;
background-color:red;
opacity:0.5;
position: absolute:
bottom: 0;
}
<div class="bg-green">
</div>
<div class="content">
this is the "body" of my page (kind of a wrapper) it needs to be like this (with negative margin top)
</div>
<footer>this is the footer</footer>
For that case you just need to set the margin and padding of body tag to 0.
body {
margin: 0;
padding: 0;
}
Or if your site have margins specified you can only set the bottom margin of body as.
body {
margin-top: 0;
margin-bottom: 0;
padding: 0;
}
body {
margin: 0;
}
.bg-green{
width:100%;
height:100px;
background-color:green;
}
.content{
width:80%;
height:300px;
margin:10px auto;
background-color:gold;
text-align:center;
}
footer{
width:100%;
height:65px;
background-color:red;
opacity:0.5;
}
<div class="bg-green">
</div>
<div class="content">
this is the "body" of my page (kind of a wrapper) it needs to be like this (with negative margin top)
</div>
<footer>this is the footer</footer>
Modify content css:
.content{
width:80%;
height:300px;
margin:10px auto;
background-color:gold;
text-align:center;
}
.bg-green{
width:100%;
height:100px;
background-color:green;
}
.content{
width:80%;
height:300px;
margin:-50px auto;
background-color:gold;
text-align:center;
padding-top:100px;
}
footer{
width:100%;
height:65px;
margin-top: -65px;
background-color:red;
opacity:0.5;
position: absolute;
bottom: 0
}
body {
margin: 0;
min-height: 100%;
padding-bottom: 100px;
position: relative;
box-sizing: border-box;
}
html {
height: 100%;
}
<div class="bg-green">
</div>
<div class="content">
this is the "body" of my page (kind of a wrapper) it needs to be like this (with negative margin top)
</div>
<footer>this is the footer</footer>
You can fix footer at bottom by position: absolute;
Updated fiddle
Use position: absolute;bottom: 0; Style in footer class
footer
{
width: 100%;
height: 65px;
background-color: red;
opacity: 0.5;
position: absolute;
bottom: 0;
}
Click Here Live Demo

How to position div's like this with CSS?

Trying to maintain an space between them, I'd like to position some divs in a specific form for my website, and then add content to them. I have been styling the pages responsively, so I would like to know if position those divs this way with responsiveness is posible. The result I guess it could be something like this:
Being X and Y the two div's I've already created (for the header and the menu) and Z the footer. The div's I'd like to put in those positions are those DIV 1, DIV 2 and DIV 3.
For the moment the two main parts above (header and menu) are styled like this:
* {
margin:0;
padding:0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
header {
width:90%;
height:30%;
margin: 0 auto;
background-color:darkblue;
color:white;
z-index: 105;
position:relative;
}
nav {
width:90%;
height:22%;
margin: 0 auto;
background-color:skyblue;
}
And the HTML I have for the moment for those DIV 1, DIV 2 and DIV 3 is this:
<div id="content">
<div id="leftinfo">
<ul>
<li>INFO</li>
<li>ABOUT</li>
</ul>
</div>
<div id="hcontent">
<div class="tophcontent">
</div>
</div>
<div id="hcontent2">
<p></p>
</div>
</div>
I've been struggling on how to position it like this, maintaining the web flow with the other divs. Any help or tips about it would be very appreciated.
I guess that you want something like
https://jsfiddle.net/2dxzr1mv/3/
*{
box-sizing:border-box;
white-space: nowrap;
}
div{
padding:0;
margin:0;
}
.div1{
width:20%;
height:100%;
background-color:red;
min-height:100vh;
display:inline-block;
}
.wrapper{
width:80%;
min-height:100vh;
display:inline-block;
}
.div2,.div3{
width:100%;
min-height:50vh;
background-color:yellow;
word-wrap: break-word;
overflow:hidden;
white-space: normal;
}
.div3{
background-color:blue;
}
I have tried something like your picture.
CSS
* {
margin:0;
padding:0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
#content {
table-layout: fixed;
display: table;
width: 100%;
height: 100%;
}
#content > div {
display: table-cell;
}
.tophcontent {
height: 40px;
margin: 0 10px;
border: 2px solid orange;
}
.midhcontent {
margin: 10px;
margin-bottom: 0;
height: calc(100% - 46px);
border: 2px solid green;
}
#leftinfo {
border: 3px solid gray;
width:120px;
}
HTML
<div id="content">
<div id="leftinfo">
<ul>
<li>INFO</li>
<li>ABOUT</li>
</ul>
</div>
<div id="header">
<div class="tophcontent">
</div>
<div class="midhcontent">
</div>
</div>
</div>
Here is my JSfiddle
Here is a sample using display: flex. It has today about 94% browser support, which I think one can consider very good.
A great benefit with this, it is fully dynamic regarding the content in each of the elements compared to float and inline-block versions.
html, body {
margin: 0;
height: 100%;
min-height: 100%;
}
* {
box-sizing: border-box;
}
.container {
min-height: 100%;
display: flex;
flex-direction: column;
}
.info, .about, .content-left, .content-right-top,
.content-right-bottom, .footer {
border: 1px solid;
}
.wrapper {
flex: 1;
display: flex;
min-height: 100%;
}
.content-left, .wrapper-inner {
flex: 1;
}
.wrapper-inner {
display: flex;
flex-direction: column;
min-height: 100%;
}
.content-right-top, .content-right-bottom {
flex: 1;
}
<div class="container">
<div class="info">
Info<br>
2 lines
</div>
<div class="about">
About<br>
in<br>
3 lines
</div>
<div class="wrapper">
<div class="content-left">
Left take all the rest of the space
Left take all the rest of the space
Left take all the rest of the space
Left take all the rest of the space
Left take all the rest of the space
Left take all the rest of the space
Left take all the rest of the space
Left take all the rest of the space
Left take all the rest of the space
</div>
<div class="wrapper-inner">
<div class="content-right-top">
Right - Top
Right - Top
Right - Top
Right - Top
Right - Top
Right - Top
Right - Top
Right - Top
</div>
<div class="content-right-bottom">
Right - Bottom
Right - Bottom
Right - Bottom
Right - Bottom
Right - Bottom
Right - Bottom
Right - Bottom
</div>
</div>
</div>
<div class="footer">
Footer<br>
has 2 lines
</div>
</div>
Is it something like this you mean ?
Codepen example
body, html{
height:100%;
}
#wrapper{
position:relative;
width: 90%;
height:100%;
margin:0 auto;
}
.left{
float:left;
width:30%;
height:100%;
background:green;
}
.top-right{
position:absolute;
right:0;
left:31%;
height:30%;
float:left;
background:blue;
}
.bottom-right{
position:absolute;
right:0;
left:31%;
bottom:0;
top:32%;
float:left;
background:red;
}

Image rest of height inside a div-Container

I have got the following code:
HTML:
<div id="mapWrapper" style="height: 624px;">
<div class="box" id="map">
<h1>Campus</h1>
<p>Description Campus Map.</p>
<img src="abc.png">
</div>
</div>
CSS:
.box {
background-color: #FFF;
border: 1px solid #CCC;
border-radius: 5px;
padding: 3px;
overflow:hidden;
height:100%;
}
#mapWrapper {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
overflow: hidden;
padding: 10px;
}
#map {
display: inline-block;
position: relative;
}
#map img {
height: 100%;
}
I want the image to take the rest of the height, that is free in the map-div. Currenty the image is set to 100% and that is why it runs out of the box at the bottom. Can someone help? Thanks!
Why not use a display:table setup, the advantage of this is that you can add as much content as you want to the first 'row' and the image will take up the remaining space (whatever is left from the table height minus the first row of content) and scale accordingly.
Demo Fiddle
HTML
<div class='table'>
<div class='row'>
<div class='cell'>
<h1>Campus</h1>
<p>Description Campus Map.</p>
</div>
</div>
<div class='row'>
<div class='cell'></div>
</div>
</div>
CSS
html, body {
height:100%;
width:100%;
margin:0;
padding:0;
}
.table {
display:table;
table-layout:fixed;
height:624px;
width:100%;
max-height:624px;
}
.row {
display:table-row;
}
.cell {
display:table-cell;
}
.row:first-of-type >.cell {
height:1%;
}
.row:last-of-type >.cell {
height:100%;
background-image:url(http://www.gettyimages.co.uk/CMS/StaticContent/1357941082241_new_banner-700x465.jpg);
background-size:contain;
background-repeat:no-repeat;
background-position:center center;
}

Div inside div (100% height) and keep footer at the bottom - JSFiddle

I've created the below jsfiddle recreating my problem, I want that the .dashboard & .inner-dashboard have always a 100% height and keep the footer always at the bottom.
http://jsfiddle.net/rv7xN/1/
HTML
<div id="wrap">
<body>
<div class="dashboard">
<div class="inner-dashboard">
</div>
</div>
</body>
</div>
<div id="footer"></div>
CSS
html,body{
height:100%;
}
#wrap {
min-height: 100%;
height: auto;
margin: 0 auto -60px;
padding: 0 0 60px;
}
#footer {
height: 60px;
background-color: blue;
}
.dashboard{
width: 100%;
height: auto;
min-height: 100%;
position: absolute;
padding-bottom: -60px;
background-color:green;
}
.inner-dashboard{
height:100%;
padding-bottom: -60px;
background-color:red;
}
Here's an example : jsFiddle
I had to modify the html to have a common container for the dashboard and the footer.
<div id="wrap">
<div class="dashboard">
<div class="inner-dashboard">
</div>
</div>
<div id="footer"></div>
</div>
I turn the wrapper (common container) in a table and the other elements in table-cell.
So even if your dashboard is height 200%, the footer's still at the bottom.
html,body{
height:100%;
}
#wrap {
position:absolute;
display:table;
height:100%;
width:95%;
padding-bottom:60px;
}
.dashboard{
width: 95%;
height: 200%;
display:table;
border:5px solid green;
}
.inner-dashboard{
width: 95%;
height: 100%;
display:table-cell;
border:5px solid red;
}
#footer {
display:table;
height: 60px;
width:95%;
border:5px solid blue;
bottom:-10px;
}
Is that it ?!
I have added modified your css and added position attribute
I hope the revision solves your issue: [UPDATE] http://jsfiddle.net/saurabhsharma/rv7xN/3/

CSS: 4 row fluid with scrollable center?

We're building an application to run on both desktop and mobile, so we're making our site as dynamic as we can.
In the new design, we've got a full width, fixed top, fixed-height header, followed by a max-width header, fixed position header, max-width footer bottom-fixed, and a center scrollable area to fill up the rest of the vertical space.
I've got the headers and footers fixed and seemingly working right, but the center body isn't filling the center space.
Here's the code and fiddle I've been working in: http://jsfiddle.net/chazthetic/KE5cX/2/
<div id="top">
<div style="float:left;color:white;">a<br /></div>
<div style="float:right;color:white;">a<br /></div>
</div>
<div id="sub">
<div id="mid">
<div id="inside">
<div id="insideHeader">
<div style="float:left;color:white;">a<br /></div>
<div style="float:right;color:white;">a<br /></div>
</div>
<div id="insideInner">
<div id="div" style="float:left;color:white;">a
<div id="div" style="float:right;color:white;">1
</div>
</div>
<div id="bot">
<div style="float:left;color:white;">a<br /></div>
<div style="float:right;color:white;">a<br /></div>
</div>
</div>
</div>
And the accompanying CSS:
* {
margin: 0;
}
html, body {
margin: 0;
}
#top {
height: 100px;
width: 100%;
background: #f00;
z-index: 5;
margin:0px;
padding:0px;
position:fixed;
top:0px;
}
#sub {
position:relative;
width: 100%;
margin:100px 0 0;
height:100%;
}
#mid {
background: #222;
width:100%;
max-width:400px;
height:100%;
margin:0 auto;
}
#push {
height: 150px;
}
#inside {
width:100%;
height:100%;
padding:0 0 0 0;
margin:50px 0 50px;
overflow:auto;
}
#insideHeader {
height:50px;
background: #0ff;
width:100%;
margin:100px auto 0;
top:0px;
position:fixed;
max-width:400px;
}
#insideInner {
height:100%;
width:100%;
display:table;
overflow:auto;
}
#inside #div {
height: 50px;
width: 50px;
background: #888;
border: 1px solid #fff;
}
#bot {
position: fixed;
bottom: 0;
height: 50px;
width: 100%;
max-width: 400px;
background: #0ff;
z-index: 2;
margin:0px auto;
left:auto;
right:auto;
}
Am I missing something to make the inside div work right? Is this solution even possible?
I figured it out!
Turns out it is possible and I was missing height:100%; on the body tag.
Once I added that, the center area filled up the space and voila, it scrolled! I also needed to add a bit of padding to the insideInner div (thanks #alireza) so the header didn't overlay any of it.