LoginSignup
0
1

SVG に background-size: 100% 100%; が適用されない時の解決方法

Last updated at Posted at 2021-02-27

現象

SVG を背景画像に指定し、縦と横を100%にしたが反映されない…:weary:

css
.hoge {
  backgournd: url(image.svg);
  background-size: 100% 100%;
}

原因

CSS でサイズを自由に変えても SVG はアスペクト比を維持したままでいるため。

解決方法

SVGpreserveAspectRatio というアスペクト比に関する属性に none を設定する。

SVG
<svg preserveAspectRatio="none"></svg>

これで縦と横100%に表示されました:blush:

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