Search code examples
htmlcsssvgsafari

Responsive svg not getting full width in safari


I have a svg that should be 100% width of the body, and it works in ie11, chrome and firefox - but in safari there's some space at both sides of the svg and I cannot get rid of it. Any help appreciated - see the fiddle here: http://jsfiddle.net/tbbtester/2apEh/

The css:

body{margin:0;padding:0;background:orange;}
.top {position: absolute;width: 100%;}
.inner{height:0;position: relative;padding-top:3.2%;}
svg{height: 100%;display:block;width: 100%;position: absolute;top:0;left:0;}
rect{stroke:none;fill:teal;}

The markup:

    <div class="top">
        <div class="inner">
            <svg viewBox='0 0 100 3.2' preserveAspectRatio="xMidYMid meet">
                <rect x="0" y="0" height="3.2" width="100"/>
            </svg>
        </div>
    </div>

Solution

  • On referring to this

    Previous SO question

    it seems that this

    preserveAspectRatio="xMidYMid meet"
    

    is the issue.

    If you change it to

    preserveAspectRatio="none"
    

    the problem is solved

    JSfiddle Demo