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>
SVG (basic support) is Fully Supported on Safari 12, which means that any user who'd be accessing your page through Safari 12 can see it perfectly. Browser incompatibility may be due to any other web technology apart from SVG (basic support).
Any height or width you set for the SVG with CSS will override the height and width attributes on the <svg> . So a rule like svg {width: 100%; height: auto;} will cancel out the dimensions and aspect ratio you set in the code, and give you the default height for inline SVG.
SVGs are pretty great when it comes to creating responsive resolution-independent logos (and other graphics, for the matter). Of course, using media queries to adapt the SVG to different media conditions goes beyond customizing logos.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With