Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox SVG image is cut off when I use external stylesheet

Given the SVG file at http://dpaste.com/756156/ when I display it in a <object> or <embed> tag, about half the time it loads in Firefox the bottom portion of the image is cut off. Using inline CSS renders it fine, and Chrome and IE9 render properly as well.

I've seen suggestions to add width and height attributes of "100%" to the SVG tag, but that hasn't helped. Any ideas?

like image 914
Hilton Shumway Avatar asked Dec 07 '25 12:12

Hilton Shumway


2 Answers

Having just suffered this issue myself [svg being clipped in firefox] I found a solution. It's a bit random and has no logic, but it fixed the issue for me.

My svg was a simple "cloud" shape drawn with Illustrator using bezier curves. No matter how many times I drew it, the right-hand side (kind of a bubble shape) was being clipped by the browser. No amount of adjusting parameters (such as viewBox, x, y, width, height) would fix it. - It was still clipped. In fact by adjusting these parameters it became obvious that it wasn't caused by any of them.

The solution was to add more data to the curve. I simply added another anchor-point on the curve that was being clipped, and hey presto it rendered properly in firefox.

Random but true. Hope this helps

like image 124
user1474932 Avatar answered Dec 10 '25 17:12

user1474932


This might be caused by Firefox rendering the SVG before loading the stylesheet, then not realizing that it needs to update it. Try changing the classname of the SVG tag in the onload event (JavaScript), as suggested by this page: http://ajaxian.com/archives/forcing-a-ui-redraw-from-javascript

If that doesn't work? Try completely regenerating the element with elm.parentNode.innerHTML += '' as suggested in the comments to this StackOverflow question: https://stackoverflow.com/a/2922034/638544

like image 36
Brilliand Avatar answered Dec 10 '25 16:12

Brilliand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!