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 Float Layout Floating Columns and Images

Oliver Sewell
Oliver Sewell
16,097 Points

Media Queries not working the columns are'nt stacking ontop?

<!DOCTYPE html>
<html>
<head>
    <title>Floats</title>
    <meta name="viewport" content="width=device-width">
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <div class="main-wrapper">
        <header class="main-header group">
            <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 the Main Banner Heading</h1>
            <p>Andouille pork chop pancetta drumstick ground round beef ribs swine brisket ham.</p>
        </div> -->
        <div class="content-row group">


                <div class="extra-content col">
                <h3>Extra 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>
            </div>

            <div class="primary-content 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. 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 likes hamburgers.</p>
            </div>
        </div>
        <footer class="main-footer">
            <p>&copy;2014 Example Layout</p>
        </footer>
    </div>
</body>
</html>
/* Page Styles
================================ */

* {
    box-sizing: border-box;
}
html,
body{
    height: 100%;
}
body {
    font: normal 1.1em/1.5 sans-serif;
    color: #222;
    background-color: #edeff0;
}

/* Layout Element Colors
================================ */

.main-header       { background-color: #384047; }
.main-logo a       { background-color: #5fcf80; }
.main-nav a       { background-color: #3f8abf; }
.primary-content   { background-color: #caebf6; }
.secondary-content { background-color: #bfe3d0; }
.main-footer       { background-color: #b7c0c7; }

/* Main Layout Styles
================================ */

.main-wrapper {
    width: 90%;
    margin: auto;
}

.main-header {

    padding: 15px;

}



.main-logo,
.main-nav li {
  float: left;
}

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

.main-logo {
  margin: 0 50px 0 0;
}


.main-logo a, 
.main-nav a {
    display: block;
    color: white;
    text-decoration: none;
    text-align: center;
    padding: 5px 15px;
    border-radius: 5px;
}
.main-banner {
    background: #dfe2e4;
    text-align: center;
    padding: 35px 15px;
}
.main-footer {
    text-align: center;
    padding-top: 5px;
    padding-bottom: 5px;
}

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

.col {
    padding: 20px;
  float: left;
  width: 30%;
}

.primary-content {
  width: 40%;
}

.col:last-child {
  float: right;
}



/* Imagery
================================ */

.feat-img {
  width: 50%;
  float: left;
  margin-top: 10px;
  margin-right: 25px;
  margin-bottom: 10px;
  border:solid 1px;
  padding: 5px;
}




/* clearfix
================================ */
.group::after {
  content: " ";
  display: table;
  clear: both;
}



/* Media Queries
================================ */

@media (max-width: 768px) {
    .main-wrapper,
    .main-nav li, 
    .main-logo,
  .col,
  .feat-img {
        width: initial;
        height: initial;
    float: initial;
    }
  .feat-img {
    width: 100%
  }
    .main-logo {
        margin-right: 0;
    }
    .extra-content {
        display: none;
    }
}

2 Answers

you need to change your width in the media query to 100% list so:

/* Media Queries
================================ */

@media (max-width: 768px) {
    .main-wrapper,
    .main-nav li, 
    .main-logo,
  .col,
  .feat-img {
        width: 100%;
        height: initial;
    float: initial;
    }
  .feat-img {
    width: 100%
  }
    .main-logo {
        margin-right: 0;
    }
    .extra-content {
        display: none;
    }
}

this way at 768px mark every thing will take up 100% of the width and create a single column, or have a "stack" effect. The current value is set in initial, this will make the classes selected the same as it is outside of the media query. I hope this helps.

David Rust
David Rust
5,562 Points

I do not think the issue is with the width in the media query. The problem is that the "extra-content" section does not stack but it disappears entirely when the media query is 'enabled'. I tried it both with the settings as 'width: initial;' and 'width: 100%'. Extra-content is not displayed either way.