CSS背景中的SVG不会显示在Safari中 [英] SVG in CSS backgrounds not showing up in Safari

查看:1013
本文介绍了CSS背景中的SVG不会显示在Safari中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在Safari中不起作用,图像不显示。这只发生在Safari,它在所有其他浏览器,我无法弄清楚为什么。这里是CSS代码:

The following code doesn't work in Safari, and the image doesn't show up. This only happens in Safari, it works in all other browsers, I can't figure out why. Here is the CSS code:

.hero {
        background: url(images/cards.svg) no-repeat center center fixed;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        background-size: cover;
        height:180px;
        width:100%;
        margin-bottom:20px;
    }

和HTML代码:

<div class="hero"></div>

更新:上述代码适用于将cards.svg转换为JPG,而是使用SVG加载速度更快。为什么SVG不会出现在Safari(7.0.1)?根据 http://caniuse.com ,支持SVG作为CSS背景图片,但不会显示。

Update: The above code works when converting the "cards.svg" into a JPG, but I would rather work with SVG as they load faster. Why would the SVG not show up in Safari (7.0.1)? According to http://caniuse.com, SVG as a CSS background image is supported but it won't display.

推荐答案

这是因为我的服务器提供的内容类型不正确。

It's because my server is serving it with an incorrect content-type.

这到我的.htaccess文件:

Had to add this to my .htaccess file:

AddType image/svg+xml .svg .svgz

这帮助我: http://css-tricks.com/snippets/htaccess/serve-svg-correct-content-type/

这篇关于CSS背景中的SVG不会显示在Safari中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆