html - 正文标签未与顶部位置对齐

标签 html css

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

    <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 示例:http://jsfiddle.net/wfrquhpf/1/

最佳答案

你可以删除额外的边距:

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>

关于html - 正文标签未与顶部位置对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26011019/

相关文章:

javascript - React 替换 CSS 中的特殊字符 `content`

html - 我无法使用 css 设置表格的上边距

html - 使用 CSS 垂直对齐元素

javascript - 从变量中的 .txt 文件获取文本

javascript - 如何在谷歌地图中自动设置信息窗口内容

html - 当一个 div 包含固定大小的背景图像时,将响应式 div 并排放置

css - 在移动设备上测试时导航栏不会折叠

css - 手写笔迭代字符串

javascript - Chrome 扩展 : Programmatically setting browser action icon causes the icon to pixelate

html - 使 flex 元素成为其文本的宽度