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 Foundations The Box Model Positioning Properties

Sean Flanagan
Sean Flanagan
33,235 Points

Wrapper div overlaps other divs

Hi.

Why does my wrapper div overlap the others?

Here's my HTML:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <title>Positioning Properties</title>
    <link rel="stylesheet" href="css/css_foundations_style.css">
    <style type="text/css">
        body { font-size: 1rem; line-height: 1.5; color: initial; }
        p { margin-bottom: 24px; }
        .wrapper { position: initial; }
    </style>
</head>
<body>
    <div class="fixed"></div>
    <div class="wrapper">
        <p>This is the first paragraph of my wrapper.</p>
        <p>And this is the second.</p>
    </div>
</body>
</html>

And my CSS:

body {
    margin: 70px 0 0;
    background: #e1e1dd;
    color: #fff;
    font: normal 1.4em sans-serif;
}

.wrapper {
    box-sizing: border-box;
    margin: 0 auto;
    padding: 25px;
    width: 80%;
    background: #fff;
    position: relative;
}

.top {
    background: #ff6347;
    position: relative;
    z-index: 10;
}

.middle {
    background: #87ceeb;
    position: absolute;
    z-index: 20;
    right: 0;
    bottom: 0;
}

.bottom {
    background: #20b2aa;
    position: relative;
    z-index: 30;
    top: -25px;
}

.fixed {
    position: fixed;
    top: 0;
    width: 100%;
    height: 60px;
    background-color: #000;
}

.wrapper div {
    width: 150px;
    height: 150px;
    text-align: center;
    line-height: 150px;
    text-shadow: 0 1px 1px rgba(0, 0, 0, .5);
}

Thanks.

Sean

3 Answers

Sean Flanagan
Sean Flanagan
33,235 Points

Hi Chedva. I've made some alterations to my HTML, as below, and it works fine now.

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <title>Positioning Properties</title>
    <link rel="stylesheet" href="css/css_foundations_style.css">
    <style type="text/css">
        body { font-size: 1rem; line-height: 1.5; color: initial; }
        p { margin-bottom: 24px; }
        .wrapper { position: initial; }
    </style>
</head>
<body>
    <div class="fixed"></div>
    <div class="wrapper">
        <div class="top">Top</div>
        <div class="middle">Middle</div>
        <div class="bottom">Bottom</div>
    </div>
</body>
</html>

Thanks.

Sean

Is it overlapping or not applying?

You are probably best using just .wrapper {} and not .wrapper div {} , as you don't have any divs within the .wrapper.

Great!