css - SVG 图像在 IE9 的 CSS 背景中不起作用

标签 css svg background-image

我无法让 SVG background-image 在 IE9 或 IE10 中工作,这可能吗? (IE11 可以)

fiddle :http://jsfiddle.net/chovy/3abhj/1/

<input type="text" class="invalid">

.invalid {
    border: 1px solid black;
    padding: 2px 10px;
    background: url(http://chovy.us.to/test/x.svg) no-repeat 0 -2px;
    background-size: 22px 22px;
}

x.svgimage/svg+xml 一起提供。

最佳答案

如果您background-image中使用此图片属性(<img>标签中),你可以使用固定的widthheight属性。它在所有流行的浏览器中都能很好地扩展 — JSFiddle .

<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24">
    <path fill="#C54C44" d="M17.5 7.4L16.1 6 12 10.1 7.9 6 6.5 7.4l4.1 4.1-4.1 4.1L7.9 17l4.1-4.1 4.1 4.1 1.4-1.4-4.1-4.1"/>
</svg>

input {
    display: block;
    margin-top: 10px;    
}

.invalid {
    border: 1px solid black;
    padding: 2px 10px;
    background: url(http://imgh.us/x_1.svg) no-repeat 0 -2px;
    background-size: 22px 22px;
}

.invalid-large {
    border: 2px solid black;
    padding: 10px 20px;
    background: url(http://imgh.us/x_1.svg) no-repeat 0 -4px;
    background-size: 44px 44px;
}

.invalid-max {
    border: 3px solid black;
    padding: 20px 20px;
    background: url(http://imgh.us/x_1.svg) no-repeat 0 -6px;
    background-size: 66px 66px;
}
<input type="text" class="invalid">
<input type="text" class="invalid-large">
<input type="text" class="invalid-max">

关于css - SVG 图像在 IE9 的 CSS 背景中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23643074/

相关文章:

html - 如何使绝对定位的div的宽度与其父div的宽度相同?

html - 如何在球数增加时增加框架的宽度

javascript - 按钮不适用于移动设备,但适用于 PC Bootstrap

javascript - Raphael JS 和文本定位?

html - 如何使用文本制作响应式全宽 X 全高背景图像

css - 在 IE 9 及以下版本的样式文本输入中没有插入点

reactjs - React Storybook 不显示 SVG 图标

javascript - Electron + react : SVG Loading Issue

javascript - 不同屏幕尺寸和设备上背景图像的完美宽度

html - 用于不同屏幕尺寸的大背景的CSS而没有滚动条