SVG for images in browsers with PNG fallback

后端 未结 6 1816
梦如初夏
梦如初夏 2020-12-13 14:24

I\'m looking to use SVG versions of a company logo on a website. At present, all current versions of major browsers (IE, Safari, Chrome, Firefox, Opera) support SVG, so this

6条回答
  •  遥遥无期
    2020-12-13 15:14

    To solve your problem w/resizing SVGs in the object tag:

    Add "preserveAspectRatio" and "viewBox" attributes to the svg tag. Open the file in a text editor and find the tag. in that tag, add the following attributes:

    preserveAspectRatio="xMinYMin meet" viewBox="0 0 {width} {height}"

    Replace {width} and {height} with some defaults for the viewBox. I use the values from the "width" and "height" attributes of the SVG tag. Save the SVG and it should now scale as expected.

    See: How do I scale a stubborn SVG embedded with the tag?

    The problem w/SVGs in the object tag, though is that they swallow the clicks.

    SVG as background-image w/PNG fallback: http://www.broken-links.com/2010/06/14/using-svg-in-backgrounds-with-png-fallback/

    My favorite is using the img tag and an onerror handler to change the src tag to a PNG.

    Another good resource: http://www.schepers.cc/svg/blendups/embedding.html

    提交回复
    热议问题