I've been struggling to make sure the svg background-img covers the entire element, regardless of the screen size it's viewed on. Unfortunately, I haven't had any success.
I attempted removing the width
and height
attributes from the svg, setting the background-size
to cover, and adding preserveAspectRatio="none"
within the svg code, but none of these solutions worked for me.
If anyone could offer some assistance, it would be greatly appreciated.
This is my SVG, mountains.svg:
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
preserveAspectRatio="none" viewBox="0 0 1024 800" xml:space="preserve">
<g>
<polygon fill="#3C5E7E" points="661.914,566.889 700.57,529.312 721.889,593.389 "/>
[additional SVG polygon elements]
</g>
</svg>
This is my HTML:
<style>
#header {
margin:0 0 0 0;
height: 110%;
background-image: url(mountains.svg);
background-size:cover;
background-position: 0 -50px;
-o-background-size: 100% 100%;
-webkit-background-size: 100% 100%;
}
</style>
<body>
<div id="header">
</div>
</body>