LoginSignup
7
7

More than 5 years have passed since last update.

簡単に画像のレティナ対応

Posted at

先に注意、
この方法は写真などは扱えません。SVGを使うためです。

今までレティナ対応と言えば

sample.html
<img src="example.jpg"
     srcset="example.jpg 1x,
             example@2x.jpg 2x,
             example@4x.jpg 4x"
     width="66" height="66"
     alt="sample image">

みたいにやってました。

でもこれって画像の枚数が増えると大変ですよね。

かと言ってSVGだけだと古いブラウザで見れなくなる。(サポートしないなら別)

なのでこんな形はどうでしょう。

sample.html
<img src="example.jpg"
     srcset="img/example.svg 2x"
     width="66" height="66"
     alt="sample image">

単純に2倍解像度のところにSVGを入れて、他の解像度は除きます。

これで2倍以上のレティナすべてに対応できます。

今時のスマホ、タブレットはほぼレティナ対応しないといけないので、
こういった方法で簡単かつ確実な対策をしてみてはいかがでしょうか。

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