javascript - 在白色背景 div 下推送页脚

标签 javascript jquery css html

我有一个名为 content 的 div,其背景颜色为白色。我遇到一个问题,我让页脚留在页面底部,但它位于内容 div 的顶部。参见图片作为引用。我希望它始终位于内容 div 下,但如果缩小,也始终位于页面底部。 我想要的一个完美例子是 http://www.jquery.com的页脚样式

这是一个演示 http://www.andrewhnovak.com/test/index.html enter image description here

HTML

   <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">

        <title>Site Demo</title>
        <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
        <link href="css/header.css" rel="stylesheet" type="text/css">
        <link href="css/mainPage.css" rel="stylesheet" type="text/css">

    <script type="text/javascript">
    function setnewcontentheight(){     
        $("#inhalt").height(Math.max($(window).height()-$("#footer").height(),$('#inhalt').height()));      
    }

    $(window).resize(function(){
        setnewcontentheight();
    });

    $(document).ready(function() {
        setnewcontentheight();
    }); 
    </script>

    </head>

CSS

 .footer { 
  z-index: 0;
  bottom: 0px;
  height: 40px;
  width: 100%;
  background-color:red;
}


.whiteBox{
    background-color:white;
    width:800px;
    height:800px;
    margin-left:auto;
    margin-right:auto;
    position:relative;
    top:80px;
    -webkit-box-shadow: 10px 11px 5px -6px rgba(0,0,0,0.43);
-moz-box-shadow: 10px 11px 5px -6px rgba(0,0,0,0.43);
box-shadow: 10px 11px 5px -6px rgba(0,0,0,0.43);
margin-bottom:100px;
 z-index: 10;
    }

最佳答案

在 setnewcontentheight 函数中,执行如下操作:

$("div.container:nth-child(5)").height(innerHeight - 40 - $("#footer").height());

(第 n 个 child 有点奇怪,您可能想为带有白纸的容器创建一个 ID 或更简单的选择器。)

关于javascript - 在白色背景 div 下推送页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28573345/

相关文章:

javascript - 查找特定 td 的第一个单词并在其他地方复制

javascript - AngularJS 或 JQuery 解析错误格式 JSON (http get)

javascript - 如何将 json 对象发送到 Controller JsonResult 方法

javascript - 扩展关于 ul li 背景图像的 Twitter Bootstrap 的正确方法是什么

jquery - 在光标(或单击的元素)位置创建 CSS 箭头?

javascript - jquery 空格键热键

html - css 菜单事件子链接显示在父链接上

css - 媒体查询在我的代码中不起作用

css - 没有固定宽度的div绕过固定宽度的父级

javascript - 如何将对象数组转换为数组?