1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

色々なサイズ・縦横比の画像をアスペクト比固定のサムネイルにピッタリする

Posted at

どんなサイズの画像でもピッタリとサムネ化

before
before.png

after
after.png

cssだけでピッタリ

css
  img {
    aspect-ratio: 4 / 3; /* 指定アスペクト比(横/縦) */
    object-fit: cover;   /* アスペクト比に合わせるように画像をトリミング */
    width: 250px;        /* 指定サイズ */
    border-radius: 10px;
  }

これは初めての案件で WordPress からランダムな画像が飛んでくるのをサムネにしないといけなくて、かなり感動したやつでした。気持ちいいです。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?