LoginSignup
2
1

More than 5 years have passed since last update.

高さが変わる要素を天地中央揃え

Last updated at Posted at 2018-05-10

ダイアログの様な中身によって高さが変わる要素を、CSSで画面中央に配置する。
transformプロパティのtlanslateを%単位で指定すると、その要素の幅・高さが基準となるので、-50%を指定することにより要素の基準点を中心に変えている。

.dialog__wrapper {
  position: relative;
  top: 50%;
  transform: translateY(-50%);
  min-width: 160px;
  max-width: 640px;
  margin-right: auto;
  margin-left: auto;
  padding-right: 24px;
  padding-left: 24px;
}

See the Pen dialog centering by Haruumi Kondo (@hal9188) on CodePen.

2
1
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
2
1