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 trial

CSS CSS Layout Techniques Display Modes Column Layout with Inline-Block

Irfan Hussain
PLUS
Irfan Hussain
Courses Plus Student 6,593 Points

primary-content collapse with main-footer when i inspect element. Why this collapse?

<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title>Practice</title> <link rel="stylesheet" href="normalize.css" /> <link rel="stylesheet" href="temp.css" /> </head> <body> <div class="main-wrapper"> <header class="main-header"> <h1 class="main-logo"> <a href="#">Logo</a></h1> <ul class="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> </header> <div class="main-banner"> <h1>This is our Main Heading!</h1> <p>Bacon ipsum dolor sit amet chicken pork</p> </div> <div class="primary-content col"> <h2>Primary Content</h2> <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. Meatloaf tri-tip turducken brisket andouille, pork belly corned beef fatback hamburger.</p> </div> <div class="secondary-content 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 l ikes hamburgers.</p> </div> <footer class="main-footer"> <p>©2014 Example Layout</p> </footer> </div> </body> </html>

/* Page Styles ================================ */

  • { box-sizing: border-box; }

body { font: normal 1.1em/1.5 sans-serif; color: #222; background-color: #edeff0; }

html, body, .main-wrapper, .col { height: 100%; } /* .main-wrapper { width: 90%; margin: auto; } / / Layout Element Colors ================================ */

.main-header { background-color: #384047; } .main-logo { background-color: #5fcf80; } .main-nav li { background-color: #3f8abf; } .primary-content { background-color: #00bfff;} .secondary-content { background-color: #0ff; } .main-footer { background-color: #00fa9a; }

/* Header, Banner and Footer Layout ================================ */

.main-header { padding: 20px; display: table; width: 100%; min-height: 120px;

} .main-logo, .main-nav, .main-nav li { display: inline-block; }

.main-logo, .main-nav { display: table-cell; vertical-align: middle; }

.main-nav { padding-left: 50px; } .main-logo, .main-nav li { border-radius: 5px; } .main-nav li { margin-right: 10px; }

.main-logo { width: 120px; }

.main-logo a, .main-nav a { color: white; text-decoration: none; display: block; text-align: center; padding: 10px 20px; }

.main-banner { text-align: center; padding: 35px 15px; background: #ebedee; } .main-footer { padding: 10px; text-align: center; }

/********* Column Layout **************/

.primary-content { width: 60%; }

.secondary-content { width: 40%; }

.col { display: inline-block; padding: 20px; margin-right: -5px; vertical-align: top; }

/* Media Queries */

@media (max-width: 768px) { .main-logo, .main-nav, .main-nav li, .col { display: block; width: initial; margin: initial; height: initial; }

.main-nav { padding-left: initial; }

.main-nav li { margin-top: 15px; }

.main-banner { display: none; } }

3 Answers

Luke Towers
Luke Towers
15,328 Points

It is because your .col elements are set to have a height of 100%, which is relative to their parent's height which is relative to the viewport size because height was defined as 100% on the html and body elements. When you open your inspector (or resize the browser window vertically), the height of those elements will change relative to the height of the viewport.

To achieve the effect you seem to be looking for, replace

html,body,.main-wrapper,.col {
    height: 100%;
}

with

html,body,.main-wrapper {
    height: 100%;
}

and

.col {
    display: inline-block;
    padding: 20px;
    margin-right: -5px;
    vertical-align: top;
}

with

.col {
    display: inline-block;
    padding: 20px;
    margin-right: -5px;
    vertical-align: top;
    min-height: 100%;
}

This changes .col from having it's height forced to 100% of its parent, and instead tells the browser that it's height should be at least 100% of its parent's height, but not to force it to be that height exactly.

Luke Towers
Luke Towers
15,328 Points

No problem, I was confused about it for a second myself :)

Luke Towers
Luke Towers
15,328 Points

Make sure that the

html,body,.main-wrapper {
    height: 100%;
}

uses height, not min-height as in my original answer, otherwise you'll run into issues.