html - CSS:相对于元素的背景位置

标签 html css

我工作的网站标题中有“两行”必须水平重复
和页脚,
我已经为两条线制作了背景重复图像

如何使“第二个背景重复图像”位置与“页脚 div”位置相同..

实际上我将顶部的两行作为一个“背景重复图像”...

HTML代码:

<body>
<div id="websiteContents">
    <div id="header">
        <div id="headerLine"></div>
        contents
        <div id="headerLine_down"></div>
    </div>
    vary contents
    <div class="footer">
        <a href="#">Home</a>
        <a href="#">about</a>
        <a href="#">contact us</a>
    </div>

</div>
</body>

CSS 代码:

body {
    background: url(../images/standard/repeat_header.png) #FFF repeat-x 0 165px;
}

#websiteContents {
    width: 1150px;
    margin: 0 auto;
}
#headerLine {
width: 1150px;
height: 4px;
background-color: #647193;
float: left;
margin-top: 14px;
 }

 #headerLine_down {
      width: 1150px;
      height: 9px;
      background-color: #2B303E;
 }

.footer {
    width: 1150px;
    background-color: #2A2F3D;
    other styles...
}

The Screenshot

网站太大了,如果你想要完整的代码我给你

谢谢大家

最佳答案

我想这对你有帮助

我改变了你的html结构

html

<div id="websiteContents">
    <div id="header">
        <div class="headerContainer">
            <div id="headerLine"></div>
            contents
            <div id="headerLine_down"></div>
        </div>
    </div>
    <div class="bodyContainer">
    vary contents
    </div>
    <div class="footer">
        <div class="footerContainer">
            <a href="#">Home</a>
            <a href="#">about</a>
            <a href="#">contact us</a>
        </div>
    </div>
</div>

CSS

body {
    background: url(../images/standard/repeat_header.png) #FFF repeat-x 0 165px;
}
body, html{
    height:100%;    
}

#websiteContents {
    height:100%;
}
#headerLine {
    width: 1150px;
    height: 4px;
    background-color: #647193;
    float: left;
    margin-top: 14px;
}

 #headerLine_down {
      width: 1150px;
      height: 9px;
      background-color: #2B303E;
 }

.footer {
    background-color: #2A2F3D;
    height:100%;
}

.headerContainer{
    width:1150px;
    margin:0 auto;
}
.bodyContainer{
    width:1150px;
    margin:0 auto;  
}
.footerContainer{
    width:1150px;
    margin:0 auto;  
}

关于html - CSS:相对于元素的背景位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17040550/

相关文章:

css - 更少的字体混合

jquery - 仅对特定的 div 使用缩放

python - 在模板django中显示元组的choicefield的值

html - 调整窗口宽度时背景图像重复

php - 使用带有多选复选框的 Ajax 帖子过滤器获取帖子

javascript - 将 HTML 转换为 PDFmake 语法

css - Bootstrap 3 中跨容器的功能区不起作用

JavaScript:切换按钮禁用属性

javascript - 触摸滚动在某些设备上不起作用

css - 在高度:100% sections之后的流中显示内容