javascript - HTML CSS Footer 在定位时做了一些奇怪的事情

标签 javascript html css web

我试图让页脚随内容移动。它有效,但它做了一些非常奇怪的事情。当我将页脚的位置设置为“相对”时,它会随着内容移动,但它会破坏背景图像,如下图所示。如果我将它设置回绝对,它会恢复正常但不会随内容移动。

底部的 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:absolute enter image description here

图像position:relative enter image description here

最佳答案

在页脚上使用相同的 position: absolute 并在 .content 上使用相同的 padding-bottom 怎么样?

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

关于javascript - HTML CSS Footer 在定位时做了一些奇怪的事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26767696/

相关文章:

javascript - 如何使用 dom 元素

html - 仅当用户仅使用缩放文本时如何在 CSS 中使用@media?

jquery - 在运行时更改 KendoPanel 的颜色

html - 仅对选定图像禁用边框或悬停效果

jquery - 制作我的侧边栏下拉菜单

javascript - 何时将样式表添加到 document.styleSheets

django 生产中未加载 css

javascript - 小程序导致错误

javascript - 一个组件的选定值应使用 native react 填充到另一个组件中

javascript - 用大写格式化字符串