Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

绝对底部几种方案 #32

Open
Open
@CodeDreamfy

Description

  • absolute
  • calc
  • table
  • flexbox

首推flex方案,其次是calcabsolute,table不推荐

flex实现方式

html,body {
 height: 100%;
 min-height: 100%;
}
body {
 display: flex;
 flex-flow: column;
}
.content {
 flex: auto;
 overflow: hidden;
 overflow-y: auto;
}
.footer {
 flex: 0 0 100px;
}

absolute

要点就是footer高度与padding-bottom一致

html, body {
 height: 100%;
}
.wrapper {
 position: relative;
 min-height: 100%;
 padding-bottom: 100px;
}
.footer {
 position: absolute;
 bottom: 0;
	height: 100px;
 width: 100%;
}

calc

html, body {
 height: 100%;
 min-height: 100%;
}
.content {
 height: calc(100vh - 100px);
}
.footer {
 height: 100px;
}

table

不推荐的原因是表格会影响其他属性,margin,border等

html, body {
 height: 100%;
}
.wrapper {
 display: table;
 min-height: 100%;
}
.content {
 display: table-row;
 height: 100%;
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /