html布局【内容小与一页时footer在页面底部,内容大与一页时footer在内容下面】...

本文介绍了一种使网页footer始终处于页面底部的方法,无论内容多少。通过设置body的min-height为100%,并使用绝对定位来固定footer位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. <html></html>的高度是窗口大小<body></body>的高度是里面内容的高度

2. 想实现这个,就要给body min-height:100%所以刚开始内容少时body的高度也可以撑满窗口大小,内容翻页时高度已经大与  100%了,就无所谓了

  为了把body做为父元素把内容都放到这里面而不是浏览器窗口,所以body设置position:relative

<html>
<head>
<title>内容小与一页时footer在页面底部,内容大与一页时footer在内容下面</title>
</head>
<body style="min-height: 100%;position: relative;">
<div style="background-color:grey;text-align:center;">
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
content</br>
</div>
<div style="position:absolute;height:50px;background-color:blue;bottom: 0;left:0;right:0;">
</div>
</body>
</html>

 

转载于:https://www.cnblogs.com/lindsayzhao103011/p/3383737.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值