html - HTML svg 标签内的标签保持黑色
问题描述
我想制作一个包含文本的圆圈(可点击)。它有效......它是可点击的......但是当我点击它时文本颜色变为黑色。然后它不会变回我想要的颜色。
<svg>
<circle cx="60" cy="60" r="50" stroke="black" stroke-width="5" fill="grey" />
<text style="text-decoration: none; color: green;" x="50" y="50"><a style="text-decoration: none; color: green;" href="#">hei</a></text>
</svg>
我在 text 和 tag 中都写了 text-decoration 和 color 的原因是因为我已经对它们都进行了尝试,但它们都不起作用。
解决方案
使用fill
而不是颜色,因为它是SVG 文本节点
请参阅下面的片段
text a {
/* fill:red;*/
}
<svg>
<circle cx="60" cy="60" r="50" stroke="black" stroke-width="5" fill="grey" />
<text x="50" y="50"><a style="text-decoration: none; fill: green;" href="#">hei</a></text>
</svg>
推荐阅读
- c# - 从逆向工程的 EF Core DbContext 创建新数据库
- list - 在 prolog 中表示表达式
- swift - SwiftUI 中带有图像和文本的 macOS 工具栏项
- node.js - 用于包装静态前端的 Node.Js 应用程序的 Docker Compose 文件
- docker - github action docker 数据库迁移失败
- java - 从多个 JSON 对象中获取密钥
- entity-framework-core - EF Core 3.1 - 从不同实体构建树结构
- xamarin - Xamarin - iOS MFMailComposeViewController.CanSendMail 导致“执行本机代码时获得 segv”
- reactjs - 隐藏多选选项 - 反应选择
- javascript - jQuery hover() 和委托