身体标签未对齐到顶部位置

时间:2014-09-24 07:28:47

标签: html css

我有一个非常简单的html网页,其中包含标题,内容和页脚部分。由于某种原因标题部分没有位于窗口的顶部,我做错了但我无法弄清楚在哪里。我可能会进一步弄乱代码试图修复它。

    <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;}

小提琴示例:http://jsfiddle.net/wfrquhpf/1/

9 个答案:

答案 0 :(得分:4)

您可以删除额外的保证金:

&#13;
&#13;
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;
}
&#13;
<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>
&#13;
&#13;
&#13;

答案 1 :(得分:3)

是,

.header-包装{宽度:100%;背景色:#000;最小高度:300像素; 保证金:30px 自动;}

试试这些,

.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;}

注意:考虑使用填充而不是间距的边距。

答案 2 :(得分:2)

这是因为您设置了以下边距:

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

.header {
    margin: 10px auto;
}

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

请查看更新后的小提琴:http://jsfiddle.net/wfrquhpf/7/

您可以改为使用填充:http://jsfiddle.net/wfrquhpf/15/

希望这有帮助

答案 3 :(得分:2)

在大多数地方使用

保证金 你可以改用填充

检查小提琴我做了一些改变

JS Fiddle

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

答案 4 :(得分:2)

这是你的CSS规则之一:

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

您定义了30px的上边距。我发现通过逐步删除规则并检查页面的外观如何。

答案 5 :(得分:0)

老兄检查一下:http://jsfiddle.net/wfrquhpf/2/

我删除了所有margin-top:30px;

答案 6 :(得分:0)

DEMO 使用保证金这是非常基本的错误尝试使用填充而不是保证金,因为它会将布局转移到最大值到顶部的保证金

*{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;}

答案 7 :(得分:0)

代码archive-yearheader-wrapper中的

都已应用保证金最高。如果你将从那里删除,问题可以解决。

答案 8 :(得分:0)

你在.archive-year .header-wrapper和.header中有3个边距可以推动它。

将其更改为此

.header-包装{宽度:100%;背景色:#000;最小高度:300像素;保证金:0px auto;} .header {背景色:#000;背景色:红色;宽度:800像素;保证金:0px auto;} .ARCHIVE年{位置:相对;宽度:100%;保证金:0px 10px; font-size:20px color:#ccc;}