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

少ないコンテンツでもフッターはスクリーンの一番下に表示する簡単なやり方CSS Flex

Posted at

Demo

HTML

<body class="Site">
  <header class="Site-header">ヘッダー</header>
  <main class="Site-content">少ない中身</main>
  <footer class="Site-footer">Footer</footer>
</body>

CSS
.Site {
  display: flex;
  min-height: 100vh;  /*ビューポートの高さに対する割合100*/
  flex-direction: column;
}

.Site-header,
.Site-footer {
  flex: none; 
  background-color: #99cc00;
}

.Site-content {
  flex: 1 0 auto;  /*flex: flex-grow flex-shrink flex-basis|auto|initial|inherit; shrinkしないように*/
  padding: var(--space) var(--space) 0;
  width: 100%;
  background-color: #666666;
}
.Site-content::after {
  content: '\00a0'; /* &nbsp; */
  display: block;
  margin-top: var(--space);
  height: 0px;
  visibility: hidden;
}
@media (--break-lg) {
  .Site-content {
    padding-top: var(--space-lg);
  }
  .Site-content::after {
    margin-top: var(--space-lg);
  }
}

.Site-content--full {
  padding: 0;
}
.Site-content--full::after {
  content: none;
}
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?