Learning
Learning

Reputation: 20051

Body tag not aligning to top position

I have a very simple html web page with header, content and footer section. for some reason header section doesn't position to top of the window, i am doing something wrong but i am not able to figure out where. I may have further mess up the code trying to fix it.

    <div class="wrapper">
        <div class="header-wrapper">
            <div class="header">
                <div class="archive-year"> ARCHIVE</div>
                <div class="title">TITLE</div>
                <div class="date">DATE</div>
            </div>
        </div>
        <div class="content">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
        </div>
        <div class="footer"><a href="http://www.website.net">FOOTER</a></div>
    </div>

CSS

html {margin:0px; padding:0px; height: 100%;}
body, form {margin:0px; padding:0px;}
.wrapper{width:100%; margin:0px auto; height:100%; font-family:Arial, Helvetica, sans-serif;}
.header-wrapper{width:100%; background-color:#000; min-height:300px;  margin:30px auto;}
.header{background-color:#000; background-color:red; width:800px;  margin:10px auto;}
.archive-year{position:relative; width:100%; margin:30px 10px; font-size:20px color:#ccc;}
.title{position:relative; width:100%; margin:10px; font-size:20px color:#fff;}
.date{position:relative; width:100%; margin:10px 10px; font-size:20px color:#1aa0e0;}
.content{position:relative; width:100%; margin:30px 10px; font-size:12px color:#000;}
.footer{position:relative; width:100%; margin:30px 10px; font-size:12px color:#000;}

Fiddle example: http://jsfiddle.net/wfrquhpf/1/

Upvotes: 2

Views: 469

Answers (9)

emmanuel
emmanuel

Reputation: 9615

It's because of the margins you have set at:

.archive-year {
    margin: 30px 10px;
}

.header {
    margin: 10px auto;
}

.header-wrapper {
    margin: 30px auto;
}

Please check the updated Fiddle: http://jsfiddle.net/wfrquhpf/7/

You could use padding instead: http://jsfiddle.net/wfrquhpf/15/

Hope this helps

Upvotes: 2

maikel
maikel

Reputation: 1789

It is one of your CSS rules:

.header-wrapper{...  margin:30px auto;}

You define a top-margin of 30px. I found that by removing rules step by step and checking how the page then looks like.

Upvotes: 2

Vitorino fernandes
Vitorino fernandes

Reputation: 15981

margin is used in most of the places u can use padding instead

check the fiddle i have made some changes

JS Fiddle

.archive-year{
    padding: 10px 10px 0 10px;
}

Upvotes: 2

Seregmir
Seregmir

Reputation: 546

U have 3 margin in .archive-year .header-wrapper and .header that push it down.

change it to this

.header-wrapper{width:100%; background-color:#000; min-height:300px; margin:0px auto;} .header{background-color:#000; background-color:red; width:800px; margin:0px auto;} .archive-year{position:relative; width:100%; margin:0px 10px; font-size:20px color:#ccc;}

Upvotes: 0

Darshak Shekhda
Darshak Shekhda

Reputation: 646

in your code archive-year and header-wrapper both have applied margin top. if you will remove from there than problem can solve.

Upvotes: 0

himanshu
himanshu

Reputation: 1797

DEMO its is very basic mistake using margin like this try using padding instead of margin because it will shift the layout to maximum amount to margin in top

*{margin:0 auto; padding:0px;}
html {margin:0px; padding:0px; height: 100%;}
body, form {margin:0px; padding:0px;}
.wrapper{width:100%; margin:0px auto; height:100%; font-family:Arial, Helvetica, sans-serif;}
.header-wrapper{width:100%; background-color:#000; min-height:300px;}
.header{background-color:#000; background-color:red; width:800px;}
.archive-year{position:relative; width:100%; margin:0px 10px; font-size:20px color:#ccc;}
.title{position:relative; width:100%; margin:10px; font-size:20px color:#fff;}
.date{position:relative; width:100%; margin:10px 10px; font-size:20px color:#1aa0e0;}
.content{position:relative; width:100%; margin:30px 10px; font-size:12px color:#000;}
.footer{position:relative; width:100%; margin:30px 10px; font-size:12px color:#000;}

Upvotes: 0

Alex Char
Alex Char

Reputation: 33228

You can to remove extra margin:

html {
    margin:0px;
    padding:0px;
    height: 100%;
}
body, form {
    margin:0px;
    padding:0px;
}
.wrapper {
    width:100%;
    margin:0px auto;
    height:100%;
    font-family:Arial, Helvetica, sans-serif;
}
.header-wrapper {
    width:100%;
    background-color:#000;
    min-height:300px;
}
.header {
    background-color:#000;
    background-color:red;
    width:800px;
    margin:0 auto;
}
.archive-year {
    position:relative;
    width:100%;
    font-size:20px color:#ccc;
}
.title {
    position:relative;
    width:100%;
    margin:10px;
    font-size:20px color:#fff;
}
.date {
    position:relative;
    width:100%;
    margin:10px 10px;
    font-size:20px color:#1aa0e0;
}
.content {
    position:relative;
    width:100%;
    margin:30px 10px;
    font-size:12px color:#000;
}
.footer {
    position:relative;
    width:100%;
    margin:30px 10px;
    font-size:12px color:#000;
}
<div class="wrapper">
    <div class="header-wrapper">
        <div class="header">
            <div class="archive-year">ARCHIVE</div>
            <div class="title">TITLE</div>
            <div class="date">DATE</div>
        </div>
    </div>
    <div class="content">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</div>
    <div class="footer"><a href="http://www.website.net">FOOTER</a>
    </div>
</div>

Upvotes: 4

winresh24
winresh24

Reputation: 687

Dude check this one: http://jsfiddle.net/wfrquhpf/2/

I Remove all your margin-top:30px;

Upvotes: 0

Nayana Adassuriya
Nayana Adassuriya

Reputation: 24766

Yes,

.header-wrapper{width:100%; background-color:#000; min-height:300px; margin:30px auto;}

Try with these,

.wrapper{margin:0px; padding:0px;width:100%;;font-family:Arial, Helvetica, sans-serif;}
.header-wrapper{width:100%; background-color:#000; min-height:300px;  margin:0px auto;}
.header{background-color:#000; background-color:red; width:800px;  margin:0px auto;}

Note: consider to uses padding instead of margin for spacing.

Upvotes: 3

Related Questions