Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS CSS Foundations The Box Model Positioning Properties

Sean Flanagan
Sean Flanagan
33,232 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,232 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!