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

I applied float, and clearfix, but the parent div still vertically collapses.

in the browser size between 769~1280px, my 'container' part collapses. I applied float to the children elements (which are 'name', 'main-nav') in the 'container'. And applied clearfix to the 'container' which is a parent of 'name' & 'main-nav'. But the 'container' part still collapses. Help please! :sob:

Here is css

/* ================================= 
  Base Element Styles
==================================== */

* {
    box-sizing: border-box;
}

body {
    font-family: 'Varela Round', sans-serif;
    line-height: 1.6;
    color: #3a3a3a;
}

p {
    font-size: .95em;
    margin-bottom: 1.8em;
}

h2,
h3,
a {
    color: #093a58;
}

h2,
h3 {
    margin-top: 0;
}

a {
    text-decoration: none;
/*  text-align:center;*/
}

img {
    max-width: 100%; 
}

.feat-img {
  padding: 10px;
  border:solid 1px rgba(218, 218, 218, 0.7);
}

.main-header,
.banner,
.main-footer {
  text-align: center;
}

.headline {
  margin: 0;
}



/* ================================= 
  Base Layout Styles
==================================== */

/* ---- Navigation ---- */

.name {
    font-size: 1.25em;
  margin:0;
}

.name a,
.main-nav a {
    text-align: center;
}

.main-nav a {
    font-size: .95em;
    color: #093a58;
    text-transform: uppercase;
}

.main-nav a:hover {
    color: #093a58;
}

/* ---- Layout Containers ---- */

.banner {
    color: #fff;
    background: #3acec2;
  padding: 20px;
  margin-bottom: 2rem;
}

.main-footer {
    background: #d9e4ea;
    padding: 2em 0;
    margin-top: 30px;
}

/* ---- Page Elements ---- */

.logo {
    width: 190px;
}

.col {
width:90%;
margin: 0 auto;
}

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

@media (min-width: 769px) {

/* ---- Nav Containers ---- */
.container {
  width: 90%;
  margin:20px auto;
  background-color: yellow;
}

.name {
 float: left;
 margin: 0;
}

.main-nav {
 float: right;
}

.main-nav li {
 float: left;
 margin:4px 0 0 10px;
}

/* ---- layout ---- */

.col {
  margin: 0 auto;
  padding:0 30px;
}

.secondary {
  width:50%;
  float:left;
}

.primary {
  width:50%;
  float:left;
}

.tertiary {
  width:100%;
}

/* ================================= 
  Media Queries 1280
==================================== */
@media (min-width: 1280px) {

.col {
  margin: 0 auto;
  padding:0 30px;
}

.secondary {
  width:25%;
  float:left;
}

.primary {
  width:50%;
  float:left;
}

.tertiary {
  float:left;
  width:25%;
}
    /* ---- Float clearfix ---- */

    .clearfix::after {
        content: " ";
        display: table;
        clear: both;
    }

}

Here is html

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Best City Guide</title>
    <link href='https://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/style.css">
</head>
<body>

    <header class="main-header">
    <div class="container clearfix">
      <h1 class="name"><a href="#">Best City Guide</a></h1>
      <ul class="main-nav">
        <li><a href="#">ice cream</a></li>
        <li><a href="#">donuts</a></li>
        <li><a href="#">tea</a></li>
        <li><a href="#">coffee</a></li>
      </ul>
    </div><!--container--->
    </header><!--/.main-header-->   

    <div class="banner">
        <img class="logo" src="img/city-logo.svg" alt="City">
        <h1 class="headline">The Best City</h1>
        <span class="tagline">The best drinks and eats in the best city ever.</span>
    </div><!--/.banner-->
    <div class="clearfix">
    <div class="secondary col">
      <h2>Welcome!</h2>
      <p>Everything in this city is worth waiting in line for.</p>
      <p>Cupcake ipsum dolor sit. Amet chocolate cake gummies jelly beans candy bonbon brownie candy. Gingerbread powder muffin. Icing cotton candy. Croissant icing pie ice cream brownie I love cheesecake cookie. Pastry chocolate pastry jelly croissant.</p>
      <p>Cake sesame snaps sweet tart candy canes tiramisu I love oat cake chocolate bar. Jelly beans pastry brownie sugar plum pastry bear claw tiramisu tootsie roll. Tootsie roll wafer I love chocolate donuts.</p>
    </div><!--/.secondary-->

    <div class="primary col">
      <h2>Great food</h2>
      <img class="feat-img" src="img/treats.svg" alt="Drinks and eats">
      <p>Croissant macaroon pie brownie. Cookie marshmallow liquorice gingerbread caramels toffee I love chocolate. Wafer lollipop dessert. Bonbon jelly beans pudding dessert sugar plum. Marzipan toffee drag&#233;e chocolate bar candy toffee pudding I love. Gummi bears pie gingerbread lollipop.</p>
    </div><!--/.primary-->

    <div class="tertiary col">
      <h2>How to get here</h2>
      <p><strong>Plane: </strong>Tiramisu caramels gummies chupa chups lollipop muffin. Jujubes chocolate caramels cheesecake brownie lollipop drag&#233;e cheesecake.</p>
      <p><strong>Train: </strong>Pie apple pie pudding I love wafer toffee liquorice sesame snaps lemon drops. Lollipop gummi bears dessert muffin I love fruitcake toffee pie.</p>
      <p><strong>Car: </strong>Jelly cotton candy bonbon jelly-o jelly-o I love. I love sugar plum chocolate cake pie I love pastry liquorice.</p>
    </div><!--/.tertiary--> 
  </div><!----clearfix-->
    <footer class="main-footer">
        <span>&copy;2015 Residents of The Best City Ever.</span>
    </footer>

</body>
</html>

Hi grace,

try this and let me know if it works for you

/* ================================= 
  Base Element Styles
==================================== */

* {
    box-sizing: border-box;
}

body {
    font-family: 'Varela Round', sans-serif;
    line-height: 1.6;
    color: #3a3a3a;
}

p {
    font-size: .95em;
    margin-bottom: 1.8em;
}

h2,
h3,
a {
    color: #093a58;
}

h2,
h3 {
    margin-top: 0;
}

a {
    text-decoration: none;
/*  text-align:center;*/
}

img {
    max-width: 100%; 
}

.feat-img {
  padding: 10px;
  border:solid 1px rgba(218, 218, 218, 0.7);
}

.banner,
.main-footer {
  text-align: center;
}





/* ================================= 
  Base Layout Styles
==================================== */

/* ---- Navigation ---- */

.name {
    font-size: 1.25em;
  padding-top:16px;
}

.name a,
.main-nav a {
    text-align: center;
}

.main-nav a {
    font-size: .95em;
    color: #093a58;
    text-transform: uppercase;
}

.main-nav a:hover {
    color: #093a58;
}

/* ---- Layout Containers ---- */

.banner {
    color: #fff;
    background: #3acec2;
  padding: 20px;
  margin-bottom: 2rem;
}

.main-footer {
    background: #d9e4ea;
    padding: 2em 0;
    margin-top: 30px;
}

/* ---- Page Elements ---- */

.logo {
    width: 190px;
}

.col {
width:90%;
margin: 0 auto;
}

ul.main-nav{
  list-style-type : none;
}

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

@media (min-width: 769px) {

/* ---- Nav Containers ---- */
.container {
  width: 90%;
  margin:20px auto;
  background-color: yellow;
}

.name {
 float: left;
 margin: 0;
}

.main-nav {
 float: right;
}

.main-nav li {
 float: left;
 margin:4px 0 0 10px;
}

/* ---- layout ---- */

.col {
  margin: 0 auto;
  padding:0 30px;
}

.secondary {
  width:50%;
  float:left;
}

.primary {
  width:50%;
  float:left;
}

.tertiary {
  width:100%;
}

/* ================================= 
  Media Queries 1280
==================================== */
@media (min-width: 1280px) {

.col {
  margin: 0 auto;
  padding:0 30px;
}

.secondary {
  width:25%;
  float:left;
}

.primary {
  width:50%;
  float:left;
}

.tertiary {
  float:left;
  width:25%;
}
    /* ---- Float clearfix ---- */

    .clearfix::after {
        content: " ";
        display: table;
        clear: both;
    }

}

2 Answers

I would add a height or min-height property to your container declaration under the first media query. Perhaps something like this:

@media (min-width: 769px) {

/* ---- Nav Containers ---- */
.container {
  width: 90%;
  margin:20px auto;
  height: 60px;
  background-color: yellow;
}

Note: I left off the closing bracket for the media query for easier copy-and-paste. I included the media query only as a context clue for faster locating. I believe this could also be accomplished by adding a border or padding property.

Also, I haven't touched CSS in awhile so someone may want to correct me, but I think you'd want to place a clearfix declaration outside of any specific media queries.

The height wouldn't be needed when doing clearfix but I think you figured out the problem being that the clearfix rule is in a media query.

Grace,

Your clearfix rule is in the 1280px media query and so it will not be applied at anything below that. You should move it to be with your mobile styles at the beginning. This way it applies at all times and you can use it wherever you need it.

Thank you Rohit, Benjamin, and Jason! I moved the clearfix up to mobile style, and it WORKS!!!!!! Hallelujah!!! (I struggled on this for all evening, and felt frustrating.)

Thank you Jason. You rock! :+1: :+1: :+1: