【发布时间】:2015-01-02 06:20:57
【问题描述】:
我正在尝试使页脚随内容移动。它有效,但它做了一些非常奇怪的事情。当我将页脚的位置设置为“相对”时,它会随内容移动,但会破坏背景图像,如下图所示。如果我将其设置回绝对值,它将恢复正常,但不会随内容移动。
似乎底部 div 不会浮在其他内容上。
HTML:
<div class="wrapper">
<!-- Top main div -->
<img src="css/images/logo2.png" class="over">
<div unselectable="on" class="top unselectable">
<ul>
<li><a href="index.html"><img src="images/home2.png" class="menu" width="218" height="50" ></a></li>
</ul>
</div>
<!-- Middle main div -->
<div class="middle">
<div class="content">
<p class="big">
Hello there!
</div>
</div>
<!-- Bottom main div -->
<div class="bottom">
</div>
</div>
CSS:
div.wrapper
{
min-height:100%;
min-width: 1280px;
position:relative; /*most likely the problem. There's a dispute between this and the footer attribute*/
}
div.top
{
height:100px;
background-color:grey;
background-repeat: repeat-x;
background: url('images/top.png');
}
div.middle
{
background-color:blue;
background-repeat: repeat;
background: url(images/bg_middle.png);
height: 100%;
width: 100%;
}
div.content
{
background: url(images/content.png);
width: 800px;
padding: 10px;
border: 1px solid #373737;
margin: 0;
word-wrap: break-word;
margin-left: auto ;
margin-right: auto ;
box-shadow: 2px 2px 2px #000000;
}
div.bottom
{
height:78px;
width: 100%;
background-color:white;
background-repeat: repeat-x;
background: url(images/bottom.png);
position:relative; /* Conflicts with the wrapper. */
bottom:0;
left:0;
}
具有位置的图像:绝对
具有位置的图像:相对
【问题讨论】:
-
您说希望“页脚随内容移动”是什么意思?将元素设置为 position:relative 对您在此处显示的实现没有实际影响。将一个元素设置为 position:absolute 会使其脱离文档的正常流程,导致其他元素在计算其位置时忽略它。
-
css-tricks.com/snippets/css/sticky-footer 这就是我的意思。当我向页面添加内容(更多文本)时,它必须向下移动页脚(不碍事)。否则文字会重叠。
-
我在调试时所做的是,我将 'border:1px solid' 添加到我的 div 或任何其他元素中,这样我就可以准确地看到它们的开始和结束位置、它们可能重叠的位置等等。这要容易得多。
-
类似的东西? codepen.io/anon/pen/kmGcz
-
是的,只有当我这样做时,我的页脚才会像上面的图片那样做奇怪的事情。不知何故,我的页脚后面出现了一条白色条纹。
标签: javascript html css web