footer吸底效果css

该文章演示了一个HTML和CSS布局技巧,当内容区域(content)为空或者不足一屏时,footer始终保持在页面底部;而当内容超过页面长度时,footer会出现在内容的最后。通过使用相对定位和绝对定位,以及适当的min-height和padding-bottom属性,实现了这种效果。

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

需求场景就是当内容为空时候,footer置于最底部
内容超过页面长度时候,排在内容最后
demo

HTML:

<body>
  <div class="wrapper">
   <div class="content">
     <ul>
       <li>1.这是内容,这是内容……</li>
       <li>2.这是内容,这是内容……</li>
       <li>3.这是内容,这是内容……</li>
       <li>4.这是内容,这是内容……</li>
       <li>5.这是内容,这是内容……</li>
       <li>6.这是内容,这是内容……</li>
       <li>7.这是内容,这是内容……</li>
       <li>8.这是内容,这是内容……</li>
       <li>9.这是内容,这是内容……</li>
       <li>6.这是内容,这是内容……</li>
       <li>7.这是内容,这是内容……</li>
       <li>8.这是内容,这是内容……</li>
       <li>9.这是内容,这是内容……</li>
       <li>6.这是内容,这是内容……</li>
       <li>7.这是内容,这是内容……</li>
       <li>8.这是内容,这是内容……</li>
       <li>9.这是内容,这是内容……</li>
     </ul>
   </div>
   <div class="footer">底部按钮</div>
  </div>
</body>

CSS:

html,
body
  height 100%
.wrapper
  position relative // 关键
  box-sizing border-box
  min-height 100% // 关键
  .content
    padding-bottom: 100px
    ul
      list-style none
      li
        height 100px
        background lightblue
.footer
  position absolute // 关键
  bottom 0
  left 0
  right 0
  height 100px // 设置固定高度
  background orange
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值