在不使用绝对位置的情况下将页脚推到底部,可以使用以下方法:
<style>
html, body {
height: 100%;
margin: 0;
}
.container {
display: flex;
flex-direction: column;
min-height: 100%;
}
.content {
flex: 1;
}
.footer {
background-color: #f5f5f5;
padding: 20px;
}
</style>
<div class="container">
<div class="content">
<!-- 主要内容 -->
</div>
<div class="footer">
<!-- 页脚内容 -->
</div>
</div>
<style>
html, body {
height: 100%;
margin: 0;
}
.container {
display: grid;
grid-template-rows: auto 1fr;
min-height: 100%;
}
.content {
/* 主要内容 */
}
.footer {
background-color: #f5f5f5;
padding: 20px;
}
</style>
<div class="container">
<div class="content">
<!-- 主要内容 -->
</div>
</div>
<div class="footer">
<!-- 页脚内容 -->
</div>
这两种方法都可以实现将页脚推到底部的效果,具体选择哪种方法取决于项目的需求和布局结构。
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云