I have a div contained site design in which i have inserted a iframe to load pages.
header stays at top well
footer stays at bottom very well
content stays at the middle well too
But the iframe isn't stretching to the full height of the container. i have not mentioned height in pixels in the style
But when i wrote
iframe {
margin:0;
padding:0;
min-height:72%;
width:100%;
background-color:#ddd;
}
HTML
<div id="container">
<div id="header"> blah blah </div>
<div id="content">
<div id="menu"> some code of menu </div>
<div id="iframeDiv" class="contentdiv">
<iframe src="#" id="#" width="100%"></iframe>
</div>
</div>
<div id="footer">blah blah</div>
</div>
CSS
html, body {
margin:0; padding:0; height:100%; width:100%;
}
iframe {
margin:0; padding:0; height:72%; width:100%;
}
#container {
min-height:100%; position:relative; width:100%;
}
#content {
padding:10px; padding-bottom:30px;
}
I tried writing styles for #iframeDiv but nothing seems to work!
it stretched till footer, but this works only in chrome. ie is not sensing the background color too. firefox displyed the backgroundcolor but not stretched to 72%. how to stretch iframe height to 72% for all browsers. ?
Check your DOCTYPE of the html page and also you can try to add CSS for the HTML and BODY tag:
html, body {
height: 100%;
}
After a long time struggle with iframe, I didnt want to enter the height value explicitly(Px). Since giving it in Px will vary for browsers i used javascript to calculate the consumed height and subtracted from the window height and assigned it to iframe using jquery. Here is what i did.
<script type="text/javascript">
$(document).ready(function() {
var windowheight = $(window).height();
var headerheight = $("#header").height();
var footerheight = $("#footer").height();
var menuheight = $("#patientMenu").height();
var frameheight = windowheight - (headerheight+footerheight+menuheight+5);
//alert(contentheight);
$('#frameset').css ({
'height' : contentheight
});
});
</script>
Related
Some of my webpages are short. In those pages, the footer might end up in the middle of the window and below the footer is whitespace (in white). That looks ugly. I'd like the footer to be at the bottom of the window and the limited content body just gets stretched.
However, if the webpage is long and you have to scroll to see the footer (or all of it), then things should behave as normal.
What's the proper way to do this with CSS? Do I need Javascript/jQuery to make this happen?
I only care about IE9+ and modern versions of other browsers. The height of the footer can change from page to page too, so I'd like to not rely on the height.
Check out this site. He has a good tutorial on how to do this with css.
I copied his css just in case Matthew's site is taken down.
html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#ff0;
padding:10px;
}
#body {
padding:10px;
padding-bottom:60px; /* Height of the footer */
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px; /* Height of the footer */
background:#6cf;
}
EDIT
Since the height of the footer is different from page to page, you could get the height of the footer and then adjust the #body padding-bottom with javascript. Here is an example using jquery.
$(function(){
$('#body').css('padding-bottom', $('#footer').height()+'px');
});
Give this a try.
It is a copy of the styles that Github uses to keep it's footer at the bottom of a page. It is a little hacky, and requires you to know the height of your footer (which may not work for your use case)
Markup
<div class="wrapper">
<div class="content"><p>Page Content</p></div>
<div class="footer-push"></div>
</div>
<footer>
<p>footer-text</p>
<img src="http://placekitten.com/100/100" alt="footer image">
</footer>
CSS (well, scss)
// our page element
html {
height:100%;
}
body {
height:100%;
}
.wrapper {
background:gray;
min-height:100%;
height: auto !important; // the magic!
height:100%;
margin-bottom:-158px; // the height of our footer + margin
}
.footer-push {
clear:both;
height:158px; // the height of our footer + margin
}
footer {
background:rgba(#a388a3,0.8);
margin-top:20px;
height:138px;
}
The important things here seem to be:
Setting height: 100% on containing elements (esp html and body)
Knowing the height of your footer, and accounting for it with a "push" element
using the combination of min-height height: auto !important and height:100%
Hope that helps!
HTML
<body>
<div class="example">
<p>Lorem ipsum dolor sit amet consectetur...</p>
</div>
<footer>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</footer>
</body>
CSS
body {
min-height: 100%;
}
footer {
position: absolute;
bottom: 0;
}
Considering that all your footer is inside the <footer> html tag, this is an easy solution using jQuery.
JS:
$(document).ready(function(){
$('body').css('padding-bottom', $('footer').height()+'px');
});
CSS:
footer {
position:absolute;
bottom:0;
}
No it's very easy set a minimum for your body height.
like this:
min-height:500px;
then the min height is 500px.
use min-height property, though not entirely reliable as some older versions may not support it. Throw in some javascript if you dont mind.
I have a website, let's take http://www.example.com. In my html I have
<div style="height:100vh;"><iframe src="http://www.example.com" style="position: relative; width: 100%; height: 100%; border:0;"></iframe></div>
Here the div has the height of 100vh but I want to get the height of example.com and automatically apply it to the div. Can I do that?
Here is a working JSFIDDLE https://jsfiddle.net/jsz9ur1g/1/
HTML
Alot of times the html doesn't expand to the full bodys height, So i added a div
called getHeight right before the body tag and gave it a position of absolute. This will ensure that it expands to 100% of the document height
<div id="getHeight">
</div>
<div id="yourElement">
</div>
CSS
As you can see i gave the HTML a min height and set the getHeight div to position absolute and gave it a height of 100%.
html{
min-height:500px;
}
#getHeight{
position:absolute;
top:0;
left:0;
height:100%;
width:100%;
}
#yourElement{
background:red;
color:#fff;
font-size:20px;
}
JS
var bodyHeight = document.querySelector("#getHeight").offsetHeight;
//or use clientHeight if you don't car about scrollbars and borders
var yourElement = document.getElementById("yourElement");
yourElement.style.height = bodyHeight + "px";
yourElement.innerHTML = "see the height of the actual document is " + bodyHeight + "px";
Currently I'm having troubles getting my layout working cross-browser. In the attached image you are able to see a preview.
height: 100%;
Some information:
div #Header
Width: 100%
height: variable
div #Sidebar (overflow-y)
Width: 300px
height: 100% minus header + footer heights
div #frameHeader
Width: 100% minus sidebar width (300px)
height: 100% minus header + footer heights
iframe #iframe (overflow-y)
Width: 100% minus sidebar width (300px)
height: 100% minus header + footer + frameheader height
div #Sticky Footer (sticky to bottom ofcourse)
Width: 100%
height: variable
I've spend countless hours trying to get this to work, I'm thinking someone should have faced this problem before? I'm hoping someone is able to give me a working cross-browser example!
Current code: http://jsfiddle.net/s6wVw/ (ugly css but I think you get the point ;))
Attachment (preview) can be found below
preview image
In your question you keep making false statements and contradicting yourself (e.g. you're talking about a sticky footer but you also imply that the page doesn't scroll - as heights of all elements sum to 100%). However, I'll try to help you none-the-less.
For the reason stated above, I've made the following assumptions:
You want the dimensions of the main areas (header, footer, sidebar, frame header, frame body) to always sum to 100%
You don't want the browser to scroll
You want scrolling in the side bar and frame body if the content overflows
The above would lead to a poor site design because if the browser/window size were to be <= 300px wide then you wouldn't be able to see any of the frame etc.. Similarly, if the browser/window height <= foot height + head height then you wouldn't see any of the sidebar, frame head, or frame body.
That being said, here is an example using jQuery, html, and css.
CSS
html, body{
margin:0; padding:0; border:0;
color:#fff;
}
#head{
width:100%;
background:#aaa;
}
#body{
width:100%;
}
#sidebar{
display:inline-block;
width:300px; height:100%;
background:#111;
vertical-align:top;
overflow:scroll;
}
#frame{
display:inline-block;
vertical-align:top;
height:100%;
}
#fhead{
width:100%;
background:#333;
}
#fbody{
width:100%;
background:#777;
overflow:scroll;
}
#foot{
position:fixed;
top:100%;
width:100%;
background:#aaa;
}
h1{margin:0; padding:10px;}
jQuery
function setSizes(){
var docWidth = $(window).width();
var docHeight = $(window).height();
var headHeight = $('#head').height();
var footHeight = $('#foot').height();
var bodyHeight = docHeight - headHeight - footHeight;
var fHeadHeight = $('#fhead').height();
$('#body').css({
height: bodyHeight
})
$('#sidebar').css({
height: bodyHeight
})
$('#frame').css({
width: docWidth - 300
})
$('#fbody').css({
height: bodyHeight - fHeadHeight
})
$('#foot').css({
"margin-top": -footHeight
})
}
$(function(){
setSizes();
var doit;
$(window).resize(function(){
setSizes();
setSizes();
})
})
HTML
<div id="head"><h1>Head Section</h1><br><br><br><br></div>
<div id="body">
<div id="sidebar"><h1>Side Bar</h1>
</div><div id="frame">
<div id="fhead"><h1>Frame Head</h1><br><br></div>
<div id="fbody"><h1>Frame Body</h1></div>
</div>
</div>
<div id="foot">
<h1>Foot Section</h1><br>
</div>
NOTES
You can put whatever content you like inside of the following divs: #head, #sidebar, #fhead, #fbody, #foot
The jQuery runs the setSizes(); function twice on window resize. This is to account for any scrollbars that may impact the available width/height
You may need to set additional overflow rules to other elements depending on what content you place in the divs
Some of my webpages are short. In those pages, the footer might end up in the middle of the window and below the footer is whitespace (in white). That looks ugly. I'd like the footer to be at the bottom of the window and the limited content body just gets stretched.
However, if the webpage is long and you have to scroll to see the footer (or all of it), then things should behave as normal.
What's the proper way to do this with CSS? Do I need Javascript/jQuery to make this happen?
I only care about IE9+ and modern versions of other browsers. The height of the footer can change from page to page too, so I'd like to not rely on the height.
Check out this site. He has a good tutorial on how to do this with css.
I copied his css just in case Matthew's site is taken down.
html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#ff0;
padding:10px;
}
#body {
padding:10px;
padding-bottom:60px; /* Height of the footer */
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px; /* Height of the footer */
background:#6cf;
}
EDIT
Since the height of the footer is different from page to page, you could get the height of the footer and then adjust the #body padding-bottom with javascript. Here is an example using jquery.
$(function(){
$('#body').css('padding-bottom', $('#footer').height()+'px');
});
Give this a try.
It is a copy of the styles that Github uses to keep it's footer at the bottom of a page. It is a little hacky, and requires you to know the height of your footer (which may not work for your use case)
Markup
<div class="wrapper">
<div class="content"><p>Page Content</p></div>
<div class="footer-push"></div>
</div>
<footer>
<p>footer-text</p>
<img src="http://placekitten.com/100/100" alt="footer image">
</footer>
CSS (well, scss)
// our page element
html {
height:100%;
}
body {
height:100%;
}
.wrapper {
background:gray;
min-height:100%;
height: auto !important; // the magic!
height:100%;
margin-bottom:-158px; // the height of our footer + margin
}
.footer-push {
clear:both;
height:158px; // the height of our footer + margin
}
footer {
background:rgba(#a388a3,0.8);
margin-top:20px;
height:138px;
}
The important things here seem to be:
Setting height: 100% on containing elements (esp html and body)
Knowing the height of your footer, and accounting for it with a "push" element
using the combination of min-height height: auto !important and height:100%
Hope that helps!
HTML
<body>
<div class="example">
<p>Lorem ipsum dolor sit amet consectetur...</p>
</div>
<footer>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</footer>
</body>
CSS
body {
min-height: 100%;
}
footer {
position: absolute;
bottom: 0;
}
Considering that all your footer is inside the <footer> html tag, this is an easy solution using jQuery.
JS:
$(document).ready(function(){
$('body').css('padding-bottom', $('footer').height()+'px');
});
CSS:
footer {
position:absolute;
bottom:0;
}
No it's very easy set a minimum for your body height.
like this:
min-height:500px;
then the min height is 500px.
use min-height property, though not entirely reliable as some older versions may not support it. Throw in some javascript if you dont mind.
I need to make my web page height to fit the height of the screen size without scrolling.
HTML
<body>
<form id="form1" runat="server">
<div id="main">
<div id="content">
</div>
<div id="footer">
</div>
</div>
</form>
</body>
CSS
#content{ background-color:#F3F3F3; margin:auto;width:70%;height:700px;}
#footer{width:100%;background-color:#666666;height:200px;}
A quick, non-elegant but working standalone solution with inline CSS and no jQuery requirements. AFAIK it works from IE9 too.
<body style="overflow:hidden; margin:0">
<form id="form1" runat="server">
<div id="main" style="background-color:red">
<div id="content">
</div>
<div id="footer">
</div>
</div>
</form>
<script language="javascript">
function autoResizeDiv()
{
document.getElementById('main').style.height = window.innerHeight +'px';
}
window.onresize = autoResizeDiv;
autoResizeDiv();
</script>
</body>
Fixed positioning will do what you need:
#main
{
position:fixed;
top:0px;
bottom:0px;
left:0px;
right:0px;
}
As another guy described here, all you need to do is add
height: 100vh;
to the style of whatever you need to fill the screen
Don't give exact heights, but relative ones, adding up to 100%. For example:
#content {height: 80%;}
#footer {height: 20%;}
Add in
html, body {height: 100%;}
Try:
#content{ background-color:#F3F3F3; margin:auto;width:70%;height:77%;}
#footer{width:100%;background-color:#666666;height:22%;}
(77% and 22% roughly preserves the proportions of content and footer and should not cause scrolling)
you can use css to set the body tag to these settings:
body
{
padding:0px;
margin:0px;
width:100%;
height:100%;
}
using this, replace your class "home" with your own
(function ($) {
$(function(){"use strict";
$('.home').css({'height':($(window).height())+'px'});
$(window).resize(function(){
$('.home').css({'height':($(window).height())+'px'});
});
});
})(jQuery);
Make sure you override the original styling by adding important.
height: 100vh !important;
I've used a CSS solution that has proved flexible.
You need choose one element to be the one that is full height. It also needs to be a parent to every content block. This can be the <body> element or anywhere in the DOM.
Additionally, you must designate one child to grow to make up whatever space is needed to stretch to fill the screen.
.content-parent {
min-height: 100vh; /* Forces to always fill the screen vertically... */
min-height: -webkit-fill-available; /* ...except on mobile, when you want to stay within the chrome */
display: flex; /* Enable content to stretch... */
flex-direction: column; /* ...vertically */
}
.filler-child {
flex-grow: 1; /* Designates this element to stretch to fill */
}
Example HTML:
<html>
<head>...</head>
<body>
<div class="parent">
<div class="hero">...</div>
<div class="content filler-child">...</div>
<div class="footer">...</div>
</div>
</body>
</html>