html - css 中的 SVG Sprite 声明的背景图像
问题描述
我有一个包含多个图像的 SVG 精灵文件。出于测试目的,我将其缩小到单个图像。
当我将图像声明为 html 正文中的实例并引用 sprite 文件中的图像 id 时,图像会正确显示。这是我对 sprite 文件的正确性和可用性的测试。
当我在 css 部分中将相同的 url 声明为背景图像时 - 它失败了。当我引用另一个 svg 文件(此处注释掉)时,该文件不是作为精灵的图像 - 它运行良好并产生图像中显示的结果。这是我对 css 声明正确性的测试。
我在这里错过了什么?为什么它不起作用?
我已经在 Codepen 中看到了很多这样的例子。谢谢。
我在 css 中测试了有无 viewBox 声明。没有效果。
这是从非精灵 svg 文件中出来的背景的样子。
我省略了 svg sprite 文件的内容,因为它运行良好。
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.footer-bg{
position: relative;
background-color: #eaeaea;
}
.footer-bg::before{
position: absolute;
content: "";
top: 0; left: 0;
width: 100%; height: 100%;
/* background: url(http://94.237.96.98/static/media/images/decor/be-lotus-2.svg) no-repeat; */
background: url(http://94.237.96.98/static/media/images/svg/be-decor-sprite_sm.svg#be-lotus-2) no-repeat;
background-size: contain;
background-position: center;
filter: saturate(0%) opacity(25%) drop-shadow(10px 10px 20px #F5D6BF);
-webkit-filter: saturate(0%) opacity(25%) drop-shadow(10px 10px 20px #F5D6BF);
-moz-filter: saturate(0%) opacity(25%) drop-shadow(10px 10px 20px #F5D6BF);
}
</style>
</head>
<body>
<svg class="sprite" role="img" ><use xlink:href="http://94.237.96.98/static/media/images/svg/be-decor-sprite_sm.svg#be-lotus-2" /></use></svg>
<div class="footer-bg">
<h1>This is my church</h1>
<h2>This is where I heal my hurts</h2>
<h3>For Tonight....</h3>
<h3>God... Is a DJ</h3>
</div>
</body>
</html>
这是 SVG 文件:
解决方案
推荐阅读
- ios - 尝试使用 TOSMBClient 使用 SMB1 上传文件时的 EXC_BAD_ACCESS
- javascript - TypeError:无法将 undefined 或 null 转换为对象 React js 材料表
- sql - 在 Excel 中过滤和显示唯一的列对
- android - 在 Android 中从 uri 显示 PDF
- user-interface - 如何让我的 gridView 滚动占据 Flutter 中的整个页面?
- javascript - 使用 Swiper 5 模拟 3d 轮子的自定义效果
- json - 扑。将 json.decode 值添加到可在 UI 中使用的 String
- jenkins - 在 Jenkins 中存储 Kubernetes 集群凭证并在声明式管道中使用
- excel - Application.DisplayAlerts = False 后出错
- scala - Scala中yield语句中的展平数组