html - 未显示 SVG 路径
问题描述
我正在尝试在 HTML 代码中创建一个 svg 应答器。我不明白为什么下面的代码没有显示我的第二条路径:
<svg width="500px" height="500px" style="border: 2px solid gray">
<rect width="490" height="490" x="5" y="5" stroke-width=3px stroke="white" fill="#a7f3ed" />
<polygon points="420 215, 495 300, 495 360, 300 360" stroke="white" stroke-width="3px" fill="#e9d5f3" />
<path d="M 6,350
C 85,355
245,400
240,495
L 5,495Z"
fill="green" stroke="white" stroke-width=3px/>
<path d="M 70,495
C 200,415
350,370
495,350
L 495,495Z"
fill="red" stroke="white" stroke-width=3px/>
</svg>
此代码显示此图片:
如果我在第一个 svg 路径中删除这些选项 "stroke="white" stroke-width=3px",我的图片将正确显示为:
<svg width="500px" height="500px" style="border: 2px solid gray">
<rect width="490" height="490" x="5" y="5" stroke-width=3px stroke="white" fill="#a7f3ed" />
<polygon points="420 215, 495 300, 495 360, 300 360" stroke="white" stroke-width="3px" fill="#e9d5f3" />
<path d="M 6,350
C 85,355
245,400
240,495
L 5,495Z"
fill="green" />
<path d="M 70,495
C 200,415
350,370
495,350
L 495,495Z"
fill="red" stroke="white" stroke-width=3px/>
</svg>
此外,看起来“stroke-width”参数没有在 svg 路径应答器中进行评估。正如您所看到的,svg 路径有一点笔画宽度,但它对于所有...的值都是相同的。
解决方案
任何一个
- 用引号将属性括起来
- 在 and之间放一个空格
3px
,/>
即stroke-width=3px />
3px/>
使解析器混淆属性何时结束以及元素何时结束
<svg width="500px" height="500px" style="border: 2px solid gray">
<rect width="490" height="490" x="5" y="5" stroke-width=3px stroke="white" fill="#a7f3ed" />
<polygon points="420 215, 495 300, 495 360, 300 360" stroke="white" stroke-width="3px" fill="#e9d5f3" />
<path d="M 6,350
C 85,355
245,400
240,495
L 5,495Z"
fill="green" stroke="white" stroke-width="3px"/>
<path d="M 70,495
C 200,415
350,370
495,350
L 495,495Z"
fill="red" stroke="white" stroke-width=3px />
</svg>
推荐阅读
- java - Spring Cloud Stream 是否支持从运行时未知的 Rabbit 队列中读取?
- linux - 如何在 bash 中读取关键字符码?
- python - 检索特定硬币对的所有数据(Python-Binance API)
- r - 如何使用 paste0 设置值?
- mysql - 在主实例上创建触发器时出现 Aurora MySQL 复制错误
- visual-studio-code - 如果__name_ ...片段如何让vs代码自动插入?
- laravel - 动态集合映射:在集合中添加缺失的记录
- python - 在 python 中实现基本元胞自动机时如何利用并行性?
- css - Mozilla 显示的 CSS 与 chrome 不同?
- variables - 在模板 bat 文件后命名文件 - 使用 CMD 代码