html - 为什么 SVG 图标不出现在标题中?
问题描述
我尝试在 h1 标题元素中添加一个 SVG 图标:
<h1>
<svg class="my-svg-inline--fa my-fa-w-18">
<use href="https://www.datanumen.com/wp-content/themes/datanumen/images/icons/icons.svg#shopping-cart"></use>
</svg> Buy Full Version Now!
</h1>
但 SVG 图标不会出现。原始 URL 是https://www.datanumen.com/outlook-repair-order/?nowprocket,我在 JSFiddle 的https://jsfiddle.net/alanccw/871v6jke/3/中创建它来演示这个问题。两者都不会显示 SVG 图标。
更新
在 JSFiddle 中进行测试时,出现以下错误:
fiddle.jshell.net/:140 Unsafe attempt to load URL https://www.datanumen.com/wp-content/themes/datanumen/images/icons/icons.svg from frame with URL https://fiddle.jshell.net/alanccw/871v6jke/3/show/?editor_console=. Domains, protocols and ports must match.
不安全尝试加载 URL svg中讨论了此问题
但是在原来的网址中,没有这样的问题,但图标仍然不显示。
解决方案
正如您所确定的,这显然不是您的 SVG 的问题:您的社交图标(例如.../icons.svg#facebook-f
)正在加载而没有任何问题,并且它们是从同一个 SVG 精灵加载的。
问题是你的父 div: cta
。您使用以下 CSS 将所有内容隐藏在其中:
single-wporder .hero-page-wporder .cta * {
display:none;
}
然后使用以下内容覆盖cta
的子元素的样式:
.single-wporder .hero-page-wporder .cta h1,
.single-wporder .hero-page-wporder .cta h1 svg,
.single-wporder .hero-page-wporder .cta h1 path {
display: inline-block;
}
问题是最后一行。shopping-cart
svg 设置在display:none
sprite 内部,因此您只需要定位它及其所有子对象即可显示它。
将您的 CSS 更新为:
.single-wporder .hero-page-wporder .cta h1,
.single-wporder .hero-page-wporder .cta h1 svg,
.single-wporder .hero-page-wporder .cta h1 svg * {
display: inline-block;
}
SVG 现在可见,您的 CTA 元素仍处于隐藏状态:
推荐阅读
- oracle - Oracle 通过传递选择查询 + SP 参数在 SP 中插入查询
- c# - 为什么这个 UTF-16 HTTP 响应在结果流中以 UTF-8 结尾?
- html - 为什么移动响应式设计不起作用
- java - 如何从 JAVA 中的接口引用访问对象状态
- sql-server - Spring Data JPA - 保存导致错误,而不是在输出语句中插入触发器
- spring - IIS 7.5 与 aws elb 问题 http 到 https j_spring_security_check.action
- flutter - Flutter 使用 CustomPainter 绘制倾斜的椭圆
- java - 如何使用在 xml 文件中定义的高度宽度和源定义 ImageView?
- java - 屏幕截图在 for 循环的下一次迭代中被覆盖,或者可能在第二次迭代中没有截图
- c - 如何使用 C 预处理器找到库的整个路径?