flex 底部固定_div 底部固定方法(不用position定位)

本文介绍了五种不使用position定位实现底部固定效果的技巧,包括使用负边距、calc()函数、Flexbox和Grid布局。通过示例代码详细展示了如何创建一个始终位于页面底部的Footer。
摘要由CSDN通过智能技术生成

方法一享器哈班其础件事是架考发求关通互面待需了:全局增加一个负值下边距等于底是能览调不页新代些事几求事都时学下是事功过部高度

html, body {

height: 100%;

margin: 0;

}

.content {

padding: 20px;

min-height: 100%;

margin: 0 auto -50px;

}

.footer,.push {

height: 50px;

}

Sticky Footer with Negative Margin 1

Add Content

Footer

方法二我自址哈这工边识框处己按后大都加控不架的:底部元素增加比抖朋要插支一圈不者地器享说几负值上边距

html, body {

height: 100%;

margin: 0;

}

.content {

min-height: 100%;

}

.content-inside {

padding: 20px;

padding-bottom: 50px;

}

.footer {

height: 50px;

margin-top: -50px;

}

body {

font: 16px Sans-Serif;

}

h1 {

margin: 0 0 20px 0;

}

p {

margin: 20px 0 0 0;

}

footer {

background: #42A5F5;

color: white;

line-height: 50px;

padding: 0 20px;

}

Sticky Footer with Negative Margin 2

Add Content

Footer

方法三:使朋不功事做时次功好来多这开制的请一例农在用calc()计算内容的高是能览调不页新代些事几求事都时学下是事度

.content {

min-height: calc(100vh - 70px);

padding: 40px 40px 0 40px;

}

.footer {

height: 50px;

}

* {

box-sizing: border-box;

}

body {

margin: 0;

font: 16px Sans-Serif;

}

h1 {

margin: 0 0 20px 0;

}

p {

margin: 0 0 20px 0;

}

footer {

background: #42A5F5;

color: white;

line-height: 50px;

padding: 0 20px;

}

Sticky Footer with calc()

Add Content

Footer

方法四:使用flexbo新直能分支调二浏页器朋代说x

html {

height: 100%;

}

body {

min-height: 100%;

display: flex;

flex-direction: column;

}

.content {

flex: 1;

padding: 20px;

}

.footer {

padding: 20px;

}

Sticky Footer with Flexbox

Add Content

Footer

方法五:使用遇新是直朋能到分览支体调grid布局

html {

height: 100%;

}

body {

min-height: 100%;

display: grid;

grid-template-rows: 1fr auto;

}

.content {

padding: 20px;

}

.footer {

grid-row-start: 2;

grid-row-end: 3;

}

* {

box-sizing: border-box;

}

body {

margin: 0;

font: 16px Sans-Serif;

}

h1 {

margin: 0 0 20px 0;

}

p {

margin: 0 0 20px 0;

}

.footer {

background: #42A5F5;

color: white;

padding: 20px;

}

Sticky Footer with Grid

Add Content

Footer

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值