在chrome浏览器中将svg图像调整为背景

时间:2013-07-05 14:50:56

标签: css html5 css3 google-chrome svg

我使用svg图像作为背景,我通过背景大小拉伸SVG图像。我希望它只是宽度明智的拉伸。它在firefox,IE9 +但Chrome中工作得非常好。请建议我如何实现它。

.homecallouts ul li {
background-image: url('blue_arow_callout.svg');
background-size: 100% 100%;
width: 21%;
height: 42px;

查看jsbin代码 http://jsbin.com/uvijuc/4/

当我在firefox中仅调整宽度拉伸但在chrome中宽度和高度都拉伸时。我只想宽度伸展。

5 个答案:

答案 0 :(得分:19)

也许在SVG文件中添加preserveAspectRatio =“none”来打开标签会有帮助吗?

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.4, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     width="282.05px" height="61.974px" viewBox="286.287 26.514 282.05 61.974" enable-background="new 286.287 26.514 282.05 61.974"
     xml:space="preserve" preserveAspectRatio="none">
<polygon fill="#0063AF" points="538.337,26.514 286.287,26.514 316.287,57.5 286.287,88.488 538.337,88.488 568.337,57.5 "/>
</svg>

JSBin example

答案 1 :(得分:6)

我没有足够的声誉进行upvote或评论,所以只有再次回答才会有效。我通过添加preserveAspectRatio =&#34; none&#34;。

解决了类似的情况
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="591.42859"
height="250.24918"
id="svg2"
version="1.1"
preserveAspectRatio="none"
inkscape:version="0.48.2 r9819"
sodipodi:docname="background.svg">

答案 2 :(得分:1)

不要使用背景大小。您需要做的是在SVG文件中具有以下宽度,高度和preserveAspectRatio值。

<svg width="100%" height="100%" preserveAspectRatio="xMidYMid slice" viewBox="..." />

请注意,为了使其正常工作,您的SVG也需要有一个有效的viewBox。它看起来确实如此。

答案 3 :(得分:1)

这是Chrome错误。事实上,回归。

http://code.google.com/p/chromium/issues/detail?id=113414

答案 4 :(得分:0)

我认为技术上镀铬在这个上是正确的,你需要调整你的背景大小值到你真正想要的。将它们保持在100%会迫使纵横比保持不变。

相关问题