1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

フッターを最下部、コンテンツを上下中央にする

Last updated at Posted at 2020-10-02

コンテンツが少ない場合でもフッターを最下部にするコードはよく見かけますが、
合わせてコンテンツを上下中央にする場合に悩んでしまったので投稿します。

HTML

body 要素直下に headermainfooter 要素を配置します。

index.html
<body>
  <header>
    <p>ヘッダー</p>
  </header>
  <main>
    <p>メイン</p>
  </main>
  <footer>
    <p>フッター</p>
  </footer>
</body>

CSS

main 要素がない場合でも footer 要素がページ下部に配置されるようにしてあります。

style.css
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
main {
  flex: 1;
}
footer {
  position: sticky;
  top: 100vh;
}

DEMO

See the Pen フッターを最下部、コンテンツを上下中央 by Takuya Mori (@taqumo) on CodePen.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?