LoginSignup
0
0

More than 3 years have passed since last update.

CSSだけで画像をトリミングする方法

Posted at

様々なサイズの画像を、全部同じサイズにトリミングしたい

1. 高さと横幅のみを指定した場合

main.css
.img {
    height: 200px;
    width: 800px;
}

=> 画像の比率がおかしくなり、変な感じに伸びてしまいます。

2. 高さと横幅、object-fitメソッドを指定

main.css
.img {
    height: 200px;
    width: 800px;
    /*これを追加するだけです*/
    object-fit: cover;
}

=> object-fitメソッドを追加するだけで、画像が同じサイズにトリミングされました。

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