I am making a web page and there are 2 fixed div's one is for the header and one is for a control bar on the left of the screen. the headers div is 50px tall and 100% wide and the side control bar is 100% tall and 50px; wide with top:50px; set to it and bottom 0px; set to it seems be working fine with not going off the page but I'm not sure yet but the real problem is when I try to put a div that takes up the remaining screen space and no more than the screen space ... so it can't go off the screen or behind the fixed div's but it goes off the screen on the bottom how do I fix this is it possible if you are wondering here is the page so far
I would suggest against using position:fixed as it has known issues with mobile devices not adhering to its display correctly (read more here: link). Instead, i would suggest using position:absolute; in a full size container, and then have your "content" use overflow:auto;
HTML
<div id="content">
<div id="top-bar">
</div>
<div id="control-bar">
</div>
<div id="main-content">
</div>
</div>
CSS
#content{
position: absolute;
top:0;
left:0;
right:0;
bottom:0;
overflow:hidden;
}
#top-bar{
position:absolute;
left:0;
top:0;
height:50px;
right:0;
background-color:blue;
}
#control-bar{
position:absolute;
top:50px;
bottom:0;
left:0;
width:50px;
background-color:red;
}
#main-content{
position:absolute;
top:50px;
left:50px;
right:0;
bottom:0;
overflow:auto;
background-color:yellow;
}
JSFIDDLE
Lay this out with flexbox and use flex-grow to have elements take up available space without overlapping or going under anything.
* {margin:0;padding:0;box-sizing:border-box;}
body,html {
min-height: 100vh;
}
body {
display: flex;
flex-direction: column;
}
header {
background: #333;
min-height: 50px;
border-bottom: 1px solid black;
}
div {
display: flex;
}
aside {
width: 50px;
background: #222;
}
.grow {
flex-grow: 1;
flex-basis: 0;
background: #555;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header></header>
<div class="grow">
<aside></aside>
<main class="grow"></main>
</div>
Related
I need a layout like header content and footer.
My requirements are...
The default position of footer Div is at bottom even no content in content Div.
When the content expand of content Div then whole body(including header,footer) need to be expand based on the content Div
I don't need position:fixed for the footer Div....
I already tried some code in my project......
CSS:
body
{
height:100%;
margin-left: 0;
margin-top: 0;
padding:0;
width:100%;
position: relative;
display:block;
}
.container
{
display:table;
width:100%;
height:100%;
}
.header
{
top:0px;
height:75px;
width:100%;
}
.content
{
width:100%;
height:auto;
position: relative;
}
.footer
{
top:5px;
bottom:0px;
height:45px;
overflow:hidden;
width:100%;
}
CODE:
<div>
<div class="header">
Header Div
</div>
<div class="content">
Content Div
</div>
<div class="footer">
Footer Div(Need it,default at bottom position)
</div>
</div>
Any Idea?
Note:I need to run this code in IE also......
add the following style to your body tag or content div element:
div {
min-height: 500px;
height:auto !important;
height: 500px;
}
This works because IE treats "height" how "min-height" is supposed to be treated.
Hi everyone my tutorial has a tree div for now. Header,container and footer. header is fixed. but if you check it in JSFiddle you see container div has a problem lags behind the header div i can not solv the problem. what can i do in my css code?
This is HTML code:
<div class="globalHeader">
<div class="globalheader-in"></div>
</div>
<div class="global_container">
<div class="container">
1 <br>2 <br>3 <br>4 <br>5 <br>
</div>
</div>
And CSS code:
.global_container {
clear:both;
width:981px;
height: auto;
margin-left:auto;
margin-right:auto;
border-right:1px solid #d8dbdf;
overflow:hidden;
background-color:#f8f8f8;
}
.container {
float:left;
width:981px;
height:100px;
background-color:red;
}
.globalHeader {
width:100%;
height:40px;
position:fixed;
background-color:#2a3542;
z-index:99999;
}
.globalheader-in {
width:981px;
height:40px;
margin-left:auto;
margin-right:auto;
border-right:1px solid #fff;
border-left:1px solid #fff;
}
Using a spacer
You can push the content of container down by adding a spacer element as the first child of the container.
.container:before {
content: ' ';
display: block;
height: 40px; /* equal to the height of the header */
}
WORKING DEMO.
Using top padding
You can also use padding-top for the container to achieve that:
.container {
width:981px;
height:100px;
/* other styles... */
padding-top: 40px;
}
WORKING DEMO.
However If you want to keep the height of the container as 100px, you should use box-sizing: border-box to calculate the height of the container including paddings and borders, as follows:
.container {
width:981px;
height:100px;
padding-top: 40px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
WORKING DEMO
I would do it like this:
http://jsfiddle.net/8eSAU/5/
.global_container{
clear:both;
position: relative;
top: 40px;
}
It was not working, because you simply hid the text beneath the fixed element.
Kolay gelsin :)
Why not add:
position:relative;
top:40px;
To .global_container {
Demo Fiddle
This assumes you wish the header to scroll with the content, in which case all you need to do per the demo is offset the top of the content by the height of the header, so it initially displays below it.
A simple padding-top will take care of that.
JSFiddle
.global_container{
clear:both;
width:981px;
height: auto;
margin-left:auto;
margin-right:auto;
border-right:1px solid #d8dbdf;
overflow:hidden;
background-color:#f8f8f8;
padding-top:40px; /* heigt of fixed header */
}
you can add padding-top to the .global_container or body
padding-top should be same as height of header.
Please find the link below for the Fiddle
Add the following to global_container class
position:absolute;
top:47px;
FIND FIDDLE HERE
With a basic three row layout:
<div class="EditorHeaderWrapper">
<h1>Title</h1>
</div>
<div class="EditorMainRowWrapper">
// Main row guts go here
</div>
<div class="EditorFooterWrapper">
</div>
How can I make it so that, when the browser height is reduced, the middle row gets complete crushed before the footer (or header) get crushed at all?
.EditorHeaderWrapper{
position:absolute;
top:0;
left:0;
right:0;
height:49px;
background-image:url('blah');
border-bottom:1px solid black;
}
.EditorMainRowWrapper{
position:absolute;
top:49px;
left:0;
right:0;
bottom:30px;
background:#f9f9f4;
overflow:hidden;
}
.EditorFooterWrapper{
position:absolute;
bottom:0;
left:0;
right:0;
height:30px!important;
background:#3c3b37;
border-bottom:1px solid black;
}
Here's a working fiddle using the code above:
http://jsfiddle.net/ZaFp8/3/
But here's the problem: When you put the code in a real browser (FF26) inside the body element (not in a fiddle), with no other styles present, it doesn't work! The footer gets cut off first! So jsfiddle is adding something that fixes the problem.
So I assume I need to add some definitions to the body, html or possibly a wrapper div with some formatting. But what, and why?
Because your footer div is absolutely positioned, you need to assign a min-height of 100% to the body and html elements to "stretch" them to the full height of the window. You also don't really need to absolutely position the other two divs - they will align from top to bottom automatically using relative positioning.
Made a few other tweaks to your code here: http://jsfiddle.net/hoppergrass/ZaFp8/10/
HTML:
<div>
<div class="EditorHeaderWrapper">
<h1>Title</h1>
</div>
<div class="EditorMainRowWrapper">
// Main row guts go here
</div>
<div class="EditorFooterWrapper">
</div>
</div>
CSS:
html {
height: 100%;
}
.EditorHeaderWrapper{
position:relative;
height:49px;
background:#3c3b37;
border-bottom:1px solid black;
}
.EditorMainRowWrapper{
position: relative;
overflow:hidden;
}
h1 {
margin: 0;
padding: 0;
}
.EditorFooterWrapper{
position:absolute;
bottom:0;
left:0;
right:0;
height:30px!important;
background:#3c3b37;
border-bottom:1px solid black;
}
body {
min-height: 100%;
margin: 0;
padding: 0;
background:#f9f9f4;
}
Edit: typos
I am trying to create a webpage layout with a header/footer (100% width, 145px height), a 'main area' between the header/footer (100% width, dynamic height), and a container around the content that is a unique background color (860px width, dynamic height but is always 'flush' against the footer).
(See Example for a visual)
The problem I am having is I can't seem to have the 'content container' always be flush with the footer when there is minimal content. Using a setup like the (original example) results in the footer floating over the content if there is a respectable/'normal' amount of content or if the window is resized.
And the Following CSS results in a gap between the content and the footer.
html,body{
margin:0;
padding:0;
height:100%;
background:yellow;
}
.wrap{
min-height:100%;
position:relative;
}
header{
background:blue;
padding:10px;
}
#content{
height:100%;
width: 400px;
margin:0 auto;
background:orange;
padding:30px;
}
footer{
background:blue;
position:absolute;
bottom:0;
width:100%;
height:60px;
}
How can I make the content container be the full height of the screen when content is minimal and have the footer 'stick' to the bottom of the page, while also being dynamic to resize appropriately if there is a normal amount of content (footer is always at the bottom of the content)?
Thank you!
FIDDLE: http://jsfiddle.net/3R6TZ/2/
Fiddle Output: http://fiddle.jshell.net/3R6TZ/2/show/
CSS
html, body {
height: 100%;
margin:0;
}
body {
background:yellow;
}
#wrapper {
position: relative;
min-height: 100%;
vertical-align:bottom;
margin:0 auto;
height:100%;
}
#header {
width: 100%;
height: 150px;
background:blue;
position:absolute;
left:0;
top:0;
}
#content {
background:pink;
width:400px;
margin:0 auto -30px;
min-height:100%;
height:auto !important;
height:100%;
}
#content-spacer-top {
height:150px;
}
#content-spacer-bottom {
height:30px;
}
#divFooter {
width:100%;
height: 30px;
background:blue;
}
HTML
<div id="wrapper">
<div id="header">Header</div>
<div id="content">
<div id="content-spacer-top"></div>
<div id="content-inner">
**Content Goes Here**
</div>
<div id="content-spacer-bottom"></div>
</div>
<div id="divFooter">Footer</div>
</div>
UPDATE
The #content-spacer-top and #content-spacer-bottom are used to pad the #content div without using padding or margin that would increase the box size past the 100% height causing problems.
In CSS3, there is the box-sizing property (more info here) that can fix this issue, but i'm assuming you don't want to depend on CSS3 features.
EDIT
Added a fix and tested down to IE7
UPDATE 2
Alternate method using :before and :after pseudo-elements instead of the spacer divs:
http://jsfiddle.net/gBr58/1/
Doesn't work in IE7 or 6 though, and to work in IE8, a <!DOCTYPE> must be declared (according to w3schools.com), but the HTML is nice and clean
UPDATE 3 (Sorry for so many updates)
Updated it to work down to IE6. I don't normally bother as my company doesn't support IE6, but it was an easy fix...
I think you need position: fixed on the footer:
footer {
width: 100%;
height: 30px;
position:fixed;
bottom:0;
}
I'm creating a sidebar with this CSS code:
.sidebar {
position: absolute;
z-index: 100;
top: 0;
left: 0;
width: 30%;
height: 100%;
border-right: 1px solid #333;
}
But the sidebar width doesn't scale when I change the browser width. How can I make the sidebar fluid?
Thanks.
Look at the height in body in CSS part.
Here is a working example for you:
Your HTML:
<div id="content">
<p>This design uses a defined body height of 100% which allows setting the contained left and
right divs at 100% height.</p>
</div>
<div id="sidebar">
<p>This design uses a defined body height which of 100% allows setting the contained left and
right divs at 100% height.</p>
</div>
Your CSS:
body {
margin:0;
padding:0;
width:100%; /* this is the key! */
}
#sidebar {
position:absolute;
right:0;
top:0;
padding:0;
width:30%;
height:100%; /* works only if parent container is assigned a height value */
color:#333;
background:#eaeaea;
border:1px solid #333;
}
#content { margin-right: 200px; }
Its kind of an odd issue, but it seems its challenging to get the background color to stretch to the bottom of both columns, when using fluid layout.
I included the workaround along with a simple 2 column fluid layout.
Try this- jsFiddle
html, body {
margin:0;
padding:0;
background:silver;
/* workaround to get the columns to look even,
change color depending on which column is longer */
}
#sidebar {
position:absolute;
left:0px;
top:0px;
padding:0;
width:30%;
background:silver;
word-wrap:break-word;
}
#content {
position:absolute;
right:0px;
width:70%;
word-wrap:break-word;
background:gray;
}