如何将html5中的footer标签置于页面最底部?底部页面布局案例分享!

猿友 2021-07-17 10:07:29 浏览数 (3014)
反馈

今天我们来讲讲:“如何将html5中的footer标签置于页面最底部?”这个问题,下面是整理的相关内容和代码,希望对大家的学习和了解有所帮助!

 具体如下:

JavaScript:

<script type="text/javascript">
    $(function(){
        function footerPosition(){
            $("footer").removeClass("fixed-bottom");
                //网页正文全文高度
                var contentHeight = document.body.scrollHeight,
                //可视窗口高度,不包括浏览器顶部工具栏
                winHeight = window.innerHeight;
            if(!(contentHeight > winHeight)){
                //当网页正文高度小于可视窗口高度时,为footer添加类fixed-bottom
                $("footer").addClass("fixed-bottom");
            } else {
                $("footer").removeClass("fixed-bottom");
            }
        }
        footerPosition();
        $(window).resize(footerPosition);
    });
</script>

CSS:

.fixed-bottom {
    position: fixed;
    bottom: 0;
    width:100%;
}

那么通过这篇文章小伙伴们都知道了:“如何将html5中的footer标签置于页面最底部?”这个问题分享,那么如果你有其他的方法也可以和大家分享你的方法,更多有关于html5的相关知识和内容我们都可以在W3Cschool中进行学习和了解更多的内容。 


0 人点赞