another HTML/CSS layout challenge - html

I've been trying to figure out a solution to this problem but haven't been 100% successful, just pseudo successful. The layout I'm looking for is one such that there is always a fixed padding/margin/height on the top and bottom of the page no matter the height of the content.
Further, the height of the content should start at the top of the page right after the padding and reach the bottom of the page right before the padding. If the height of the content isn't large enough, it should span the whole page. If it is larger than the height of the page, the scrollbar should appear as in normal situations, but the top/bottom paddings need to be preserved.
To view an example of my pseudo-solution to this, check out this fiddle...
http://jsfiddle.net/UnsungHero97/uUEwg/1/ ... height not large enough
http://jsfiddle.net/UnsungHero97/uUEwg/8/ ... height too large
The problem with my solution is that if there is a background image, it will be covered up where the padding is. So how do I extend my solution such that if there is a background image, it will still be visible where the top/bottom paddings are? I would prefer this to be a HTML/CSS only solution, which is what makes this really hard!
Let me know if I need to clarify anything.

I came up with this:
http://jsfiddle.net/bKsad/
Due to the use of box-sizing: border-box, it won't work in IE7 and older.
It should work in all modern browsers.
You could replace #padding-bottom with #content:after. Beware IE8 though, I couldn't quite get it working.
CSS:
html, body {
margin: 0;
padding: 0;
height: 100%;
}
body {
background: url(http://dummyimage.com/100x100/f0f/fff);
}
#wrapper {
margin: 0 auto;
width: 300px;
height: 100%;
padding: 15px 0;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
#content {
background-color: #C9E6FF;
min-height: 100%;
}
#padding-bottom {
height: 15px;
}
HTML:
<div id="wrapper">
<div id="content">
<p>some content</p>
<p>some content</p>
<p>some content</p>
</div>
<div id="padding-bottom"></div>
</div>

Is this perhaps what you were after => http://jsfiddle.net/Husar/uUEwg/24/ ?

The best and easy solution for this issue is this one. In this case
you need two heights :
Windows height
Side-bar navigation height
Then check of windows height is less than div, then you need to increase the height of content area
$( document ).ready(function() {
var navh = $(".side-nav").height();//ide-nav
var h = window.innerHeight;
if (navh >h){
$("#mainBody").height(navh);
}
})

Related

How to have main intro div always show full width of window

How can I have my first div always be full-screen (of the browser not computer), and then supporting divs show underneath.
I want to replicate the layout of this site
http://checklandkindleysides.com
In the simplest form, I just want:
First section to be full height and width of window
Supporting content to be a specific size and not full-screen
Thanks
You need to give the html, body and full height div a height of 100%.
CSS
html,
body {
height: 100%;
}
body {
padding: 0;
margin: 0;
}
.full-height-content {
height: 100%;
overflow-y: auto; /* margin overflow fix */
}
HTML
<div class="full-height-content">
This is your full height content
</div>
<div class="page-content">
<p>This is your standard page content</p>
</div>
Here is a codepen:
http://codepen.io/anon/pen/aNyQJm

cannot get full width of page and image divs arent sized properly

I've put a codepen example to explain:
http://codepen.io/djnutron/pen/gPJzGJ
Basically, I'm wondering why the html and body tags will not go full width. My screen is 1920x1080, but the html tag refuses to be 1920 - it always goes to 1903 for some reason? Any idea why? Also the parent div of the img tag is adding some padding somewhere - because the img is 1900 wide and the surrounding div goes to 1903? Im wondering where this padding is coming from? Ive tried adding display:block, and also vertical-align:top to the image, but no dice...
Here's the code:
HTML
<div class="gallery" >
<div class="gallery-cell">
<div class="innerG">
<img src="http://lorempixel.com/image_output/animals-q-c-1900-850-2.jpg" />
</div>
</div>
<div class="gallery-cell">Lorem ipsum dolor sit</div>
</div>
CSS
html, body {
padding: 0;
margin: 0;
}
* {
box-sizing: border-box;
}
.gallery-cell {
padding: 0;
margin: 0;
}
I believe this is the case:
The scrollbar is 17 pixels wide
Also the div you have called "innerG" is display block, so it has the width of the full page. No padding is hidden anywhere. :)
Just zoom out and you will see that it's size is changing to match the screen width
If you want to have full body width all the time, you can set this in CSS:
html, body {
padding: 0;
margin: 0;
min-width: 1920px;
}
You could try to set both your HTML and Body to width: 100%;
Is there any content that is longer than the window's height? If so, might be the scroll bar as Silviagreen said.

Pushing the footer at the bottom of my page with a margin at the top

I often use the method of an empty div to make my footer stay at the bottom of my page. The code idea is following:
<body>
<div id="canevas">
<article>My website's content</article>
<div id="push"></div>
</div>
<footer id="footer">Here my footer</footer>
</body>
The css:
html, body {
height: 100%;
margin:auto;
}
#canevas {
min-height: 100%;
height: auto;
margin-bottom: -33px;
}
#footer, #push {
height: 33px;
}
Today I'm looking for how to add a margin-top on my #caneva div without breaking the footer. Do you have any idea?
Note that my page's content can have many different size (a lot less and a lot more than 100% of the screen height).
Here a fiddle with previous code.
If using padding-top is an option, you could use box-sizing: border-box to calculate the width and height of the box including padding and border, as follows:
#canevas {
min-height: 100%;
margin-bottom: -33px;
padding-top: 50px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
WORKING DEMO.
Also it's worth noting that border-box value is supported on IE8+.
Alternatively, you could add another spacer element as the first child of the #canevas element to push down the content, as follows:
.spacer {
height: 50px;
}
<body>
<div id="canevas">
<div class="spacer"></div>
<article>My website's content</article>
<div id="push"></div>
</div>
<footer id="footer">Here my footer</footer>
</body>
This will have a promising browser support :)
UPDATED DEMO.
For further info, you could refer my answer on a similar question on SO here:
Position footer at bottom of page having fixed header
If what you mean is to keep the height of the page, then the answer is to also add margin-bottom: -63px; to your #caneva div. This way basically only the top of the '#caneva div' will change, the rest of the page will remain the same.
I created an updated fiddle here for you.

CSS: make middle div take whole free space of the window height (min-height)

Can anyone help me with position my content block?
It looks good if there are a lot of content, but not when window higher than content block.
Actualy I need that "content" block on my picture teked all free space (height) and thats why footer stick to the bottom.
I have next HTML markup:
<div>
<header></header>
<nav class="breadcrumbing"></nav>
<section class="left_nav"></section>
<section class="content"></section>
<footer></footer>
</div>
With this CSS:
html,body{width:100%;margin:0;padding:0;}
body{background-color:#629302}
body>div{width:400px;height:100%;margin:0 auto;background-color:#FFF;}
body>div>header{height:50px;background-color:#9dc155}
body>div>nav.breadcrumbing{display:block;height:10px;margin:0;padding:0;}
body>div>section.left_nav{width:172px;margin:8px 20px;float:left;background-color:#cdef88}
body>div>section.content{width:168px;float:left;}
body>div>footer{padding:19px 19px 22px;background-color: #e58b04;clear:left;}
I allready tried answers from Is it possible to get a div's height to be 100% of an available area? and some same questions but with no luck.
ALso my live HTML has backgroun-images, so I can't just put footer to the bottom with position:absolute.
There I post my HTML to preview: jsfiddle.
UPD: scaled live preview:
You will have to set the html and body height property to 100%; then you can set the footer height to 100%; this will tell the main container elements the real meaning of 100% and it will work.
Your updated fiddle
Basically, these are the rules you have to add:
html, body {
height: 100%;
}
footer {
height: 100%;
}
Update
Ok, I might have misunderstood your requirements, here is a cleaner example:
Working example
Basically, what you additionally do in this example is having your wrapper element display:table with an height: 100%, then you make your footer display as table-row.
Important note: This solution uses display-table which is compatible only for IE8+. If supporting IE7 is an issue for you, then you have two solutions that I can think of out of my head:
Either you use a fixed-width footer, push it below the content and then pull it back with a combination of negative margin and padding.
Or you fallback to support of older browser by putting your footer in position using some javascript.
This the breakdown of the code:
HTML
<div class="wrapper">
<header></header>
<section class="main-content">
{child elements of your main-content area}
</section>
<footer></footer>
</div>
CSS
html, body {
height: 100%;
margin: 0;
}
.wrapper {
display: table;
margin: 0 auto;
height: 100%;
}
.main-content {
display: table-row;
height: 100%;
}
footer {
display: table-row;
}
Here's an updated fiddle
The crux of this is setting the body to be absolutely positioned to the viewport. From there, if you wanted to allow it to scroll as you normally would, then you would change the footer's position to fixed and the content div's CSS to this:
body>div>div{width:400px;height:100%;margin:0 auto;background-color:#FFF;
position:absolute; top: 0; bottom: 0; overflow-y:auto;}
I've wrapped your content div in another to allow for the automatic margins to center your page, and then defined the footer's box sizing as border-box to account for the padding you're adding to it as well.

How to make HTML content occupy all the available height?

Please, consider the following jsFiddle - http://jsfiddle.net/mark69_fnd/hwCuB/ (you can find the code after the body of the question).
It represents a trivial example of the classic header, content, footer HTML layout. Notice that:
The content never overlaps with the footer. Resizing the window will finally create a vertical scrollbar rather than move the content over the footer.
There are no redundant scrollbars.
No absolute heights, except of the footer, which may be assumed to be no higher than 2em.
The content height is less than the available height between the header and the footer.
I would like to keep the first three properties, but change the last one, so that the content height is the full height between the header and the footer. And I would like to do so without resorting to javascript.
How can I do so, if at all?
EDIT
The given html and css are just an example. You are free to change them as long as the final result satisfies the conditions of my question.
EDIT2
Apparently, I am not very clear on what I want to achieve with the content. Here is what I have now:
Notice how the content does not extend the full height available to it between the header and the footer.
What I am after is this:
(edited in mspaint, I do not know to do it really)
EDIT3
Added an except clause to the 3rd condition:
except of the footer, which may be assumed to be no higher than 2em.
HTML:
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.7.3/build/cssreset/reset-min.css">
</head>
<body>
<div class="container">
<div class="header">
Header goes here.
</div>
<div class="content">
<div class="innerWrapper">
Content goes here.
</div>
</div>
<div class="footer">
<div class="status">
Footer goes here.
<div>
</div>
</div>
</body>
</html>​
CSS:
html, body {
height: 100%;
width: 100%;
}
.container {
position: relative; /* needed for footer positioning*/
margin: 0 auto;
height: auto;
min-height: 100%;
background-color: #ddd;
}
.content {
padding: 0em 0em 2em; /* bottom padding for footer */
background-color: #bbb;
}
.footer {
position: absolute;
width: 100%;
bottom: 0; /* stick to bottom */
}
.status, .header {
background-color: #999;
border: solid 1px #000000;
}
​
There might be couple ways to do this, but the only ways i can think of at the moment all involve setting/knowing the height of your header and footer.
Here is one using display:table http://jsfiddle.net/fLnkf/
There may be other solutions depending on if your requirements allow you to change your html or use CSS3.
hope this helps!