分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

将HTML的页脚固定在屏幕下方

发布时间:2023-09-06 01:06责任编辑:傅花花关键词:HTML
/********************************************************************* * ????????????????将HTML的页脚固定在屏幕下方 * 说明: * ????处理的方法好像是比较多的,个人还是比较倾向于用JS进行处理。 * * ??????????????????????????????????2017-8-25 深圳 龙华樟坑村 曾剑锋 ********************************************************************/一、参考文档: ???1. 将footer固定在页面底部的实现方法 ???????https://segmentfault.com/a/1190000004453249二、采用代码: ???1. HTML: ???????<body> ???????????<header>header</header> ???????????<main>main content</main> ???????????<footer>footer</footer> ???????</body> ???2. CSS: ???????html,body{margin:0;padding: 0;} ???????header{background-color: #ffe4c4;} ???????main{background-color: #bdb76b;} ???????footer{background-color: #ffc0cb;} ???????/* 动态为footer添加类fixed-bottom */ ???????.fixed-bottom {position: fixed;bottom: 0;width:100%;} ???3. JS: ???????$(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"); ???????????????} ???????????} ???????????footerPosition(); ???????????$(window).resize(footerPosition); ???????});

将HTML的页脚固定在屏幕下方

原文地址:http://www.cnblogs.com/zengjfgit/p/7427260.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved