4
3

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でエレメントの高さを画面の高さに合わせました。

Last updated at Posted at 2016-11-12

表示するエレメントを画面の高さに合わせたいと思いました。

height: 100vhを使う

heightに100vhを指定すると画面高さになりました。

 .item {
    min-height: 100vh;
 }

min-heightにしているのは、itemクラスの中身が増えたときに高さが広がってほしいからです。

高さを指定すると中央揃えしたくなる

高さを指定すると内容量のバランスをとるために垂直方向の中央揃えをしたくなります。
align-items: center;を指定して上下垂直方向を中央揃えにしました。

 .item {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
 }

最終的に上記のようになりました。縦方向の画面いっぱいに広がる垂直方向に中央揃えされたテキストが表示されるようになります(☝ ՞ਊ ՞)

4
3
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
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?