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.

ひとりCSSAdvent Calendar 2022

Day 23

insetプロパティでつくる上下左右中央揃え

Last updated at Posted at 2022-12-22

ひとりCSS Advent Calendar 2022 23日目です。

inset プロパティを使ってみます

inset プロパティとは

top, right, bottom, left を指定できるショートハンド。

inset で作る上下左右中央

背景画像を置いたボックスを画面の上下左右中央に配置するようにしました。

image.png

<div class="wrapper">
  <div class="img-box"></div>
</div>
.wrapper {
  height: 100vh;
  position: relative;
}

.img-box {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 150px;
  height: 180px;
}

メモ

  • 途中まで margin:auto を指定し忘れていた
    • 指定しないと中央に行かない
  • top, right, bottom, left それぞれに 0 を指定せずに済むの楽だな

参考

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?