7

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>
user3755716
  • 75
  • 1
  • 5

3 Answers3

12

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

Community
  • 1
  • 1
Paulie_D
  • 107,962
  • 13
  • 142
  • 161
0

preserveAspectRatio attribute can have 3 different kind of value meet slice none. Check the DEMO.

so if you use

<svg viewBox='0 0 100 3.2' preserveAspectRatio="xMidYMid none">

instead of

<svg viewBox='0 0 100 3.2' preserveAspectRatio="xMidYMid meet">

you problem might solve.

Kheema Pandey
  • 9,977
  • 4
  • 25
  • 26
0

Adding a set width and height of 100% on the SVG element fixed it on Safari for me.

parker_codes
  • 3,267
  • 1
  • 19
  • 27