javascript - 固定顶部导航 + 使用 Jquery 的粘性页脚

标签 javascript jquery html css

我在尝试同时使用固定顶部导航和粘性页脚时遇到问题,而不会将页脚隐藏在距底部 40 像素的位置。我正在使用的 jquery 脚本旨在解决此问题,但事实并非如此。我不能使用 Bootstrap 或类似的东西。所以这是我唯一的选择。

HTML

<div id="container">
<nav role="navigation" id="cssmenu">
<ul>
    <li class="active"><a href="index.html">Home</a></li>

    <li class="has-sub"><a href="pages/courses.html">Courses</a>
        <ul>
            <li><a href="pages/courses/media.html"><span>Digital Media</span></a></li>
            <li><a href="pages/courses/webdev.html"><span>Web Development</span></a></li>
            <li><a href="pages/courses/journalism.html"><span>Journalism</span></a></li>
            <li class="last"><a href="pages/courses/infocomms.html"><span>Information & Communications</span></a></li>
        </ul>
    </li>
</ul>
<div id="wrapper">
    <header role="banner" id="banner">
        <div class="not-fullscreen background" style="background-image:url('http://www.minimit.com/images/picjumbo.com_IMG_6643.jpg');" data-img-width="1600" data-img-height="1064">
            <div class="content-a">
                <div class="content-b">
                    <h1>header1</h1>
                    <h2>header 2</h2>
                </div>
            </div>
        </div>
    </header>

    <div class="content">   


            <main role="main" id="skipnav">

                <p>Intro paragraph</p>




            </main>
    </div>
</div>
    <footer class="footer" id="footer">
        <div class="container2">
        <p>footer</p>
      </div>
    </footer>

</div>

Jquery 脚本 -

$(document).ready(function(){
var footer_height=$("#footer").height();
$("#wrapper").css({
    'padding-bottom' : footer_height
});
});

可以找到css here

可以找到完整的网站here

提前致谢。

最佳答案

不用jquery就可以只用css

#footer {
 bottom: 0;
 position: fixed;

}
nav {
  top : 0;
 position: fixed;

}

关于javascript - 固定顶部导航 + 使用 Jquery 的粘性页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28805855/

相关文章:

javascript - 刷新后拖动时带有输入值的 jQuery slider

jquery - 添加元素后重新初始化 jQuery UI droppable

c++ - 文本对齐 : Right in <span> or <div> (with HTML and C++)

javascript - 表单验证中的文本输出跑出输出消息框

javascript - 使用 Mapbox GL JS 计算出现次数(geojson 属性)

javascript - Crockford 原型(prototype)继承

javascript - 为什么登录时 html event.currentTarget 为 null

javascript - document.getElementById ("id").value 的最佳用途是什么

php - Jquery - 从 mysql 查询获取数据

html - 如何移动搜索栏内的搜索按钮?