LightningWrist
LightningWrist

Reputation: 937

why is fixed position messing up my alignment?

I am trying to keep the header still and have the rest of the content scroll underneath it. I am able to achieve this, however when I put a fixed position on my two header divs the break out of the margin auto.

css:

.structure {
    width:960px;
    padding:20px;
    margin:0px auto 0px auto;
    background:#121212;
    border-left:5px #F06BA8 solid;
    border-right:5px #F06BA8 solid;
}
.header_home_structure {
    width:960px;
    margin:0px auto 0px auto;
    position:fixed;
    height:80px;
}
.header_home_bg {
    width:100%;
    background:#121212;
    border-bottom:3px #F06BA8 solid;
    height:80px;
    position:fixed;
}

html:

<body>
    <div class="header_home_bg clearfix">
        <div class="header_home_structure clearfix">
            </div>
        </div>
    <div class="structure clearfix">
    </div>
</body>

Upvotes: 7

Views: 4657

Answers (1)

Mr. Alien
Mr. Alien

Reputation: 157384

Just use position: fixed on the container div, don't use it twice

Demo

.structure {
    width:960px;
    padding:20px;
    margin:0px auto 0px auto;
    background:#121212;
    border-left:5px #F06BA8 solid;
    border-right:5px #F06BA8 solid;
}
.header_home_structure {
    width:960px;
    margin:0px auto 0px auto;
    height:80px;
}
.header_home_bg {
    width:100%;
    background:#121212;
    border-bottom:3px #F06BA8 solid;
    height:80px;
    position:fixed;
}

Upvotes: 5

Related Questions