Stretch SVG background image?

一曲冷凌霜 提交于 2019-12-10 14:23:49

问题


It's easy to stretch a png background image:

.stretched-logo-bg {
    background: url("../img/curve.png") center center no-repeat;
    background-size: 100% 100%;
}

this won't work with an SVG background though

.stretched-logo-bg {
    background: url("../img/curve.svg") center center no-repeat;
    background-size: 100% 100%;
}

it won't get stretched, it will maintain its aspect ratio and just center.

At least in Chrome 52


回答1:


If you need to override the preserveAspectRatio of the SVG you are displaying you can use an SVG fragment identifier to do that e.g.

.stretched-logo-bg {
    background: url("../img/curve.svg#svgView(preserveAspectRatio(none))") center center no-repeat;
    background-size: 100% 100%;
}



回答2:


I don't believe that you can make a SVG to distort like you can with PNGs.

However, if you are mostly supporting modern browsers, you can add preserveAspectRatio="none" attribute to the SVG tag.

For example:

<svg version="1.1" preserveAspectRatio="none" .. etc`


来源:https://stackoverflow.com/questions/39418463/stretch-svg-background-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!