css - 为什么背景图像在 ^IE9 上不重复

标签 css internet-explorer sass

我在页面的各个部分之间创建了一个过渡,我希望尽可能保持结构化。现在的问题是背景图像在 IE9、IE10 和 IE11 上不重复(测试了这些)

过渡样式:

.transition {
    position:absolute;
    z-index: 100;
    width:100%;
    height: 50px;
    background-size: auto 100%;
    background-repeat: repeat-x;
    bottom:-1px;
    background-image: url(../img/transition.svg);
}

它确实适用于 safari、chrome、firefox(较新版本)

最佳答案

当我之前必须实现这一点时,我找到了 this邮政。它声明如下:

For whatever reason, Internet Explorer 10 does not support the repeating of SVG-based background images out of the box.

但是可以解决这个问题:

We need to make Internet Explorer 10 preserve the aspect ratio by slicing the image accordingly. For this to happen, preserveAspectRatio="none slice" should be added to the <svg> like so:

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 149 50" enable-background="new 0 0 149 50" xml:space="preserve" preserveAspectRatio="none slice">

(IE 9 和 IE 11 也是如此)

在 IE9(我一直使用的浏览器)中,这会将 svg 拉伸(stretch)到屏幕的长度,因为 background-size宽度设置为 100% .

因此您需要设置 background-size到您希望重复的图像的大小。例如,当我测试时,我设置了 background-size成为40px 50px这将 svg 设置为 40px x 50px 图像,然后在 div 的宽度和高度上重复它。

关于css - 为什么背景图像在 ^IE9 上不重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40401022/

相关文章:

html - 如何将 HTML 页面垂直分成 4 个部分

html - 根据标题大小设置边距顶部? HTML CSS

html - 导航宽度不随内容改变

c# - ASP.NET sass/scss 在运行时和编译时编译?

javascript - 多重计算无法正常工作

javascript - IE 不支持 Array includes 或 String includes 方法

css - 具有适当行为的华丽网页按钮,可以做到吗?

jquery - 在 Internet Explorer 中使用 .append() 刷新列表框的内容

html - 防止 Prepos 处理某些 scss 文件?

css - 在 SASS Compass 中禁用浏览器前缀?