Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialorange sky
Front End Web Development Techdegree Student 4,945 Pointscolumns wont reach my footer, and my footer is not touching the bottom of the page
Hello!
There are 2 problems with this code:
If you run this code you will see that the columns dont touch the footer and the footer isnt at the bottom of the screen where it normally is.
Can you please tell me how to fix these 2 problems
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="css/normalize.css">
<title>Building a grid</title>
<style>
img{
width:100%;
}
.grid-container{
padding-right:10px;
padding-left:10px;
margin:0 auto;
}
html, body{
height:100%;
}
.col{
min-height:100%;
}
@media(min-width:768px)
{
.grid-container >[class^="grid-"]{
float:left;
padding-left:10px;
padding-right:10px;
min-height:1px;
margin-left:2%;
}
.grid-container >[class^="grid-"]:first-child{
margin-left:0;
float:left;
}
.grid-container >[class^="grid-"]:last-child{
float:right;
}
.grid-1{
width:6.5%;
}
.grid-2{
width:15%;
}
.grid-3{
width:23.5%;
}
.grid-4 {
width: 32%;
}
.grid-5 {
width: 40.5%;
}
.grid-6 {
width: 49%;
}
.grid-7 {
width: 57.5%;
}
.grid-8 {
width: 66%;
}
.grid-9 {
width: 74.5%;
}
.grid-10 {
width: 83%;
}
.grid-11 {
width: 91.5%;
}
.grid-12 {
width: 100%;
}
.group::after{
content:"";
display:table;
clear:both;
}
}
</style>
<style>
body{
font:normal 1.1em/1.5 sans-serif;
color:#222;
background:#edeff0;
}
.feat-img{
padding:5px;
border:1px solid;
}
.main-header{
padding:20px;
background:#384047;
}
.main-logo{
margin:0;
border-radius:5px;
font-size:1.5em;
}
.main-nav{
text-align:center;
}
.main-logo a, .main-nav a{
text-decoration:none;
color:white;
text-align:center;
padding:10px 20px;
display:block;
border-radius:5px;
}
.main-logo {
background-color:#5fcf80;
}
.main-nav a{
background-color:#3f8abf;
}
.main-banner{
display:none;
}
.col{
padding:10px;
}
.main-nav li{
margin-top:8px;
}
@media(min-width:768px)
{
*{
box-sizing:border-box;
}
body{
padding-top:75px;
}
.main-header{
position:fixed;
top:0;
width:100%;
}
.col{
background:yellow;
}
.main-footer{
padding:20px;
text-align:center;
background:red;
}
.feat-img{
width:25%;
float:left;
margin:5px 20px 10px 0;
}
.main-nav li{
display:inline-block;
}
.main-banner{
text-align:center;
background: #dfe2e4;
padding:50px 15px;
margin-bottom:20px;
}
}
</style>
</head>
<body>
<header class="main-header group">
<div class="grid-container">
<h1 class="grid-2 main-logo"><a href="#">Logo</a></h1>
<ul class="grid-8 main-nav">
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
<li><a href="#">Link 4</a></li>
</ul>
</div>
</header>
<div class="main-banner">
<h1>This is the main banner </h1>
<p>Andouille pork chop pancetta drumstick ground round beef ribs swine brisket ham.</p>
</div>
<div class="grid-container group">
<div class="grid-8 col">
<h2>Primary Content</h2>
<img class="feat-img" src="http://lorempixel.com/400/300" />
<p>Bacon ipsum dolor sit amet chicken pork ground round brisket corned beef ball tip shank tail salami filet mignon ham hock pork belly venison shankle. Pig kielbasa drumstick sausage pork chop boudin. Chicken t-bone salami pork chop, beef ribs kevin ham tri-tip beef venison biltong brisket.</p>
<p>Venison strip steak meatball chicken, brisket prosciutto sirloin. Capicola drumstick brisket tri-tip salami. Chicken beef jerky, tail turkey prosciutto cow ham sirloin boudin tenderloin.</p>
</div>
<div class="grid-4 col">
<h3>Secondary Content</h3>
<p>Strip steak tenderloin kevin swine meatloaf capicola, doner beef turducken pancetta corned beef pork loin shoulder.</p>
<hr>
<p>Pork filet mignon leberkas, tail swine venison pancetta turkey shoulder brisket chalkers likes hamburgers.</p>
<hr>
<p>Meatball pastrami shoulder, brisket ribeye spare ribs turkey tongue strip steak t-bone.</p>
</div>
</div>
<footer class="main-footer">
<p>©2014 Example Layout</p>
</footer>
</body>
</html>
MUZ140970 Shaune Muringani
11,962 Pointsmake sure all your parent containers have a height of 100%
MUZ140970 Shaune Muringani
11,962 Pointsmake sure all your parent containers have a height of 100%
4 Answers
Zakery Kates
5,280 PointsUnless you preset the height on both of your columns (or use tables - yuck) then you can't guarantee both your column divs are going to be the same height.
What you need is to have a jQuery script test to see which column is taller, then apply the taller column's height to the smaller column's height. Thus making them both the same height.
You can see how it all comes together on codepen: http://codepen.io/zakkates/pen/mbhig
Or, here's the jQuery I used:
<script>
function columnheight() {
var column1height = $("div.grid-8").height();
var column2height = $('div.grid-4').height();
if (column1height < column2height) {
$('div.grid-8').height(column2height)
} else {
$('div.grid-4').height(column1height);
}
}
columnheight();
</script>
orange sky
Front End Web Development Techdegree Student 4,945 PointsHello Zakery,
Thank you for your thorough response. I am trying to run your code, but I have a few question.
1) I added the jquery plugin at the bottom of this code, but when I tried to test in by calling an alert in columnHeight(), the function did not run. Am I using the wrong Jquery version?
if (column1height < column2height) { $('div.grid-8').height(column2height);
} 2) What is supposed to do ($('div.grid-8').height(column2height);). I am pretty sure it is not returning anything. I think it is setting the column1height to the height of column2height, in case colum 1 is shorter than column 2. Am I right?
3) What can I add to my code, to make it work with the code you gave me?
thanks!!
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="css/normalize.css">
<title>Building a grid</title>
<style>
img{
width:100%;
}
.grid-container{
padding-right:10px;
padding-left:10px;
margin:0 auto;
}
html, body{
height:100%;
}
.col{
min-height:100%;
}
@media(min-width:768px)
{
.grid-container >[class^="grid-"]{
float:left;
padding-left:10px;
padding-right:10px;
min-height:1px;
margin-left:2%;
}
.grid-container >[class^="grid-"]:first-child{
margin-left:0;
float:left;
}
.grid-container >[class^="grid-"]:last-child{
float:right;
}
.grid-1{
width:6.5%;
}
.grid-2{
width:15%;
}
.grid-3{
width:23.5%;
}
.grid-4 {
width: 32%;
}
.grid-5 {
width: 40.5%;
}
.grid-6 {
width: 49%;
}
.grid-7 {
width: 57.5%;
}
.grid-8 {
width: 66%;
}
.grid-9 {
width: 74.5%;
}
.grid-10 {
width: 83%;
}
.grid-11 {
width: 91.5%;
}
.grid-12 {
width: 100%;
}
.group::after{
content:"";
display:table;
clear:both;
}
}
</style>
<style>
body{
font:normal 1.1em/1.5 sans-serif;
color:#222;
background:#edeff0;
}
.feat-img{
padding:5px;
border:1px solid;
}
.main-header{
padding:20px;
background:#384047;
}
.main-logo{
margin:0;
border-radius:5px;
font-size:1.5em;
}
.main-nav{
text-align:center;
}
.main-logo a, .main-nav a{
text-decoration:none;
color:white;
text-align:center;
padding:10px 20px;
display:block;
border-radius:5px;
}
.main-logo {
background-color:#5fcf80;
}
.main-nav a{
background-color:#3f8abf;
}
.main-banner{
display:none;
}
.col{
padding:10px;
}
.main-nav li{
margin-top:8px;
}
@media(min-width:768px)
{
*{
box-sizing:border-box;
}
body{
padding-top:75px;
}
.main-header{
position:fixed;
top:0;
width:100%;
}
.col{
background:yellow;
}
.main-footer{
padding:20px;
text-align:center;
background:red;
}
.feat-img{
width:25%;
float:left;
margin:5px 20px 10px 0;
}
.main-nav li{
display:inline-block;
}
.main-banner{
text-align:center;
background: #dfe2e4;
padding:50px 15px;
margin-bottom:20px;
}
}
</style>
<script>
function columnheight() {
var column1height = $("div.grid-8").height();
var column2height = $('div.grid-4').height();
if (column1height < column2height) {
$('div.grid-8').height(column2height);
} else {
$('div.grid-4').height(column1height);
}
alert(column1height);
}
columnheight();
</script>
</head>
<body>
<header class="main-header group">
<div class="grid-container">
<h1 class="grid-2 main-logo"><a href="#">Logo</a></h1>
<ul class="grid-8 main-nav">
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
<li><a href="#">Link 4</a></li>
</ul>
</div>
</header>
<div class="main-banner">
<h1>This is the main banner </h1>
<p>Andouille pork chop pancetta drumstick ground round beef ribs swine brisket ham.</p>
</div>
<div class="grid-container group">
<div class="grid-8 col">
<h2>Primary Content</h2>
<img class="feat-img" src="http://lorempixel.com/400/300" />
<p>Bacon ipsum dolor sit amet chicken pork ground round brisket corned beef ball tip shank tail salami filet mignon ham hock pork belly venison shankle. Pig kielbasa drumstick sausage pork chop boudin. Chicken t-bone salami pork chop, beef ribs kevin ham tri-tip beef venison biltong brisket.</p>
<p>Venison strip steak meatball chicken, brisket prosciutto sirloin. Capicola drumstick brisket tri-tip salami. Chicken beef jerky, tail turkey prosciutto cow ham sirloin boudin tenderloin.</p>
</div>
<div class="grid-4 col">
<h3>Secondary Content</h3>
<p>Strip steak tenderloin kevin swine meatloaf capicola, doner beef turducken pancetta corned beef pork loin shoulder.</p>
<hr>
<p>Pork filet mignon leberkas, tail swine venison pancetta turkey shoulder brisket chalkers likes hamburgers.</p>
<hr>
<p>Meatball pastrami shoulder, brisket ribeye spare ribs turkey tongue strip steak t-bone.</p>
</div>
</div>
<footer class="main-footer">
<p>©2014 Example Layout</p>
</footer>
<script src="http://code.jquery.com/jquery.js"></script>
</body>
</html>
Aaron Coursolle
18,014 PointsWriting this comment for anyone looking at this answer in the future:
It is not only having the script in the wrong place that would cause a failure. The poster didn't have a closing script tag in the above code.
Zakery Kates
5,280 Pointswell, you have to call the jquery before you can use it. :)
Your script must come AFTER you load the jQuery library. Also, this should all be loaded IN THE FOOTER so that the DOM has a chance to load before you start resizing things.
So, it should be like this:
<script src="http://code.jquery.com/jquery.js"></script>
<script>
function columnheight() {
var column1height = $("div.grid-8").height();
var column2height = $('div.grid-4').height();
if (column1height < column2height) {
$('div.grid-8').height(column2height);
} else {
$('div.grid-4').height(column1height);
}
alert(column1height);
}
columnheight();
</script>
Zakery Kates
5,280 PointsYou should now check out CSS Flex Box
display:flex; https://css-tricks.com/snippets/css/a-guide-to-flexbox/
MUZ140970 Shaune Muringani
11,962 PointsMUZ140970 Shaune Muringani
11,962 Pointsmake sure all your parent containers have a height of 100%