0
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 3 years have passed since last update.

フッターを下部に固定する方法

Posted at

はじめに

フッターをウィンドウの下部に固定する方法をまとめました。
ページのコンテンツ量が少ない場合でもフッターが下部に固定されるようにします。

方法

まずはHTMLを用意します。

html
<body>
~略~
  <div class="footer-box">
    <span>Copyright © MSY Inc., Ltd. All rights reserved.</span>
  </div>
</body>

次にCSSを用意します。

bodyを画面の大きさにしておきたいのでmin-height: 100vhを設定します。
positionでbodyの子要素であるフッターをbottom: 0で最下部に位置するようにします。
このままだとコンテンツがはみ出てしまうので、フッターの高さ分 padding-bottomを与えます。今回はリセットCSSで指定しているのここでは記述していないが、bodyにbox-sizing: border-box; でpaddingを含めた高さになるようにします。

css
body {
  min-height: 100vh;
  position: relative;
  padding-bottom: 46px;
}

.footer-box {
  width: 100%;
  text-align: center;
  background-color:  #e7e7e7;
  padding: 15px 0;
  position: absolute;
  bottom: 0;
}
.footer-box span {
  font-size: 12px;
}
0
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
0
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?