Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Responsive svg not getting full width in safari

Tags:

html

css

safari

svg

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>
like image 823
user3755716 Avatar asked Jun 19 '14 09:06

user3755716


People also ask

Does Safari support SVG?

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).

How do I change SVG full width?

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.

Can SVGs be responsive?

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.


1 Answers

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

like image 79
Paulie_D Avatar answered Oct 24 '22 21:10

Paulie_D