简体   繁体   English

HTML CSS页脚在定位时做一些奇怪的事情

[英]HTML CSS Footer does something weird when positioning

I am trying to make the footer move with the content. 我试图使页脚随内容移动。 It works, but it does something very weird. 它可以工作,但是却做得很奇怪。 When I set the position of the footer to "relative" it moves with the content as it should, but it ruins the background image as seen in the image below. 当我将页脚的位置设置为“相对”时,它随内容移动,但它破坏了背景图像,如下图所示。 If I set it back to absolute, it will be back to normal but it won't move with the content. 如果将其设置为绝对值,它将恢复为正常值,但不会随内容移动。

Seems like the bottom div won't float over the other content. 好像最下面的div不会浮在其他内容上。

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

Image with position:absolute 位置图像:绝对 在此处输入图片说明

Image with position: relative 位置图像:相对 在此处输入图片说明

How about you use same position: absolute on the footer and padding-bottom on the .content ? 您如何使用相同的position: absolute在页.content position: absolute ,在.content上为padding-bottom

div.content {
    padding-bottom: 78px;//height of the footer
}

Just move the div up a bit: top and z-index. 只需将div向上移动一点:top和z-index。 Only z-index if it isn't on top. 如果z-index不在顶部,则仅显示。

div.bottom
{
    height:78px;
    width: 100%;
    background-color:white;
    background-repeat: repeat-x;
    background: url(images/bottom.png);
    position:relative;
    bottom:0;
    left:0;
    top:-15px;
    z-index:2;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM