如何使页面底部始终在最底下

方法一:footer 高度固定+绝对定位

<html>

<head>

<style type="text/css">

html{height:100%;}

body{min-height:100%;margin:0;padding:0;position:relative;}

.header{background-color: #ffe4c4;}

.main{padding-bottom:100px;background-color: #bdb76b;} /* main的padding-bottom值要等于或大于footer的height值 */

.footer{position:absolute;bottom:0;width:100%;height:100px;background-color: #ffc0cb;}

</style>

</head>

<body>

<div class="header">header</div>

<div class="main">main content</div>

<div class="footer">footer</div>

</body>

</html>

效果:

 

 

 还有2中方式,这个是我常用的一种。

第二种是:footer高度固定+margin负值。样式和第一张类似,就是 footer{  margin-top: -100px}

第三中就是footer高度任意,+js,

就是判断当前页面内容是否大于可视窗口高度,

转载于:https://blog.csdn.net/u012258564/article/details/72771188

posted @   以后。h  阅读(1472)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示