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

elements lay over together.

The paragraph in a body and a footer section lay over when I change the window size. How can I fix it?

https://w.trhou.se/l7c8sn3rl5

This is my CSS code

/* ================================= 
  Base Element Styles
==================================== */
* {
 box-sizing:border-box;
}


body {
    line-height: 1.6;
    color: #3a3a3a;
}

a { 
    color: #000;
    text-decoration: none;
}

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

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

.container {
 padding-left: 1em;
 padding-right: 1em;
 background-color: lavender;
 max-width: 100%;

}

.name {
  margin:0;
}

.main-header {
    background: #3acec2;
  padding:1em 0;
}

.wrap {

  margin-bottom: -89px;
  background-color: tomato;
  min-height: 100vh;
}

.main-footer {
  text-align:center;
    padding: 0em 0em;
    background: blue;
  color: #fff;
  padding: 2em 2em;
}


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


@media(min-width: 769px) {


 .container {
  width:70%;
  max-width: 1000px;
  margin: 0 auto;
  }

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

This is my html code

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Best City Guide</title>
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
  <div class="wrap">
      <header class="main-header">
        <div class="container">
          <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>
      </header>
      <div class="container">
        <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>

        <h2>Great food</h2>
        <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>
    </div>

    <footer class="main-footer">
      <span>&copy;2015 Residents of The Best City Ever.</span>
    </footer>

</body>
</html>

1 Answer

Konrad Traczyk
Konrad Traczyk
22,287 Points

Hi, I've checked you code.

The reason your footer overlays the .wrap container is the minus margin you gave to the .wrap element.

I recommend you to delete the minus margin property and set the min-height on this element using calc function like this

.wrap {
    background-color: tomato;
    min-height: calc(100vh - 89px);
}

After setting that you'll notice unwanted white space between last paragraph inside .wrap and footer. You have two ways to get rid of it. However at first give your .container which is outside the header second class called .main-container then you can:

Set padding-bottom of your .container to some minimum value like 1px

.main-container {
    padding-bottom: 1px;
}

else

Target last-child or last-of-type pseudo selector to your paragraph.

.main-container p:last-child {
    margin-bottom: 0;
}