How does one make a SVG background that stretches rather than tiles?

后端 未结 3 440
遇见更好的自我
遇见更好的自我 2020-12-14 06:59

I have a SVG background I want to use, and I can\'t figure out how to make it stretch over the whole page, let alone be a background. Could someone help?

(The W3Scho

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-14 07:18

    I just figured it out. On your tag you need to:

    • remove the width and height properties ex: width="375" height="137"
    • add this property preserveAspectRatio="none"
    • add the viewbox property (containing your original width and height that you just removed viewBox="0 0 375 137"

    In your css file on the element that contains your svg background:

    • add the property: background-size: 100% 100%;

    The key issue for me was that my svg file didn't contain the viewbox property.

提交回复
热议问题