html - SVG gradient passes gradient color to the next SVG
问题描述
I have an issue with SVG icons. The first SVG icon passes its color to the next one like that:
The second icon should have red gradient.
Here's a snippet example:
<svg width="128" height="128" viewBox="0 0 128 128" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="64" cy="64" r="64" fill="url(#paint0_linear)"/>
<path d="M31.7628 63.2679L59.7926 85.5881L98.3475 34.6986" stroke="white" stroke-width="18"/>
<defs>
<linearGradient id="paint0_linear" x1="2.5" y1="-6.5" x2="101.5" y2="124.5" gradientUnits="userSpaceOnUse">
<stop stop-color="#26A212" stop-opacity="0.4"/>
<stop offset="0.0001" stop-color="#26A212" stop-opacity="0.47"/>
<stop offset="1" stop-color="#26A212"/>
</linearGradient>
</defs>
</svg>
<svg width="128" height="128" viewBox="0 0 128 128" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="64" cy="64" r="64" fill="url(#paint0_linear)"/>
<line x1="35.636" y1="92.636" x2="92.636" y2="35.636" stroke="white" stroke-width="18"/>
<line x1="35.364" y1="35.636" x2="92.364" y2="92.636" stroke="white" stroke-width="18"/>
<defs>
<linearGradient id="paint0_linear" x1="2.5" y1="-6.5" x2="101.5" y2="124.5" gradientUnits="userSpaceOnUse">
<stop stop-color="#26A212" stop-opacity="0.4"/>
<stop offset="0.0001" stop-color="#B81818" stop-opacity="0.47"/>
<stop offset="1" stop-color="#B81818"/>
</linearGradient>
</defs>
</svg>
When I remove the first icon, color of failure
icon is red as expected:
Here's a snippet example:
<svg width="128" height="128" viewBox="0 0 128 128" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="64" cy="64" r="64" fill="url(#paint0_linear)"/>
<line x1="35.636" y1="92.636" x2="92.636" y2="35.636" stroke="white" stroke-width="18"/>
<line x1="35.364" y1="35.636" x2="92.364" y2="92.636" stroke="white" stroke-width="18"/>
<defs>
<linearGradient id="paint0_linear" x1="2.5" y1="-6.5" x2="101.5" y2="124.5" gradientUnits="userSpaceOnUse">
<stop stop-color="#26A212" stop-opacity="0.4"/>
<stop offset="0.0001" stop-color="#B81818" stop-opacity="0.47"/>
<stop offset="1" stop-color="#B81818"/>
</linearGradient>
</defs>
</svg>
I use https://figma.com for creating icons and I export these icons as SVG. Do you have any idea what's wrong with this?
解决方案
根据 Danny '365CSI' Engelman。当我们给每个元素这个唯一的 id 时,id 是相同的,这就是结果。谢谢丹尼,我也忽略了身份证。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
</style>
</head>
<body>
<svg width="128" height="128" viewBox="0 0 128 128" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="64" cy="64" r="64" fill="url(#paint0_linear)"/>
<path d="M31.7628 63.2679L59.7926 85.5881L98.3475 34.6986" stroke="white" stroke-width="18"/>
<defs>
<linearGradient id="paint0_linear" x1="2.5" y1="-6.5" x2="101.5" y2="124.5" gradientUnits="userSpaceOnUse">
<stop stop-color="#26A212" stop-opacity="0.4"/>
<stop offset="0.0001" stop-color="#26A212" stop-opacity="0.47"/>
<stop offset="1" stop-color="#26A212"/>
</linearGradient>
</defs>
</svg>
<svg width="128" height="128" viewBox="0 0 128 128" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="64" cy="64" r="64" fill="url(#paint01_linear)"/>
<line x1="35.636" y1="92.636" x2="92.636" y2="35.636" stroke="white" stroke-width="18"/>
<line x1="35.364" y1="35.636" x2="92.364" y2="92.636" stroke="white" stroke-width="18"/>
<defs>
<linearGradient id="paint01_linear" x1="2.5" y1="-6.5" x2="101.5" y2="124.5" gradientUnits="userSpaceOnUse">
<stop stop-color="red" stop-opacity="0.4"/>
<stop offset="0.0001" stop-color="red" stop-opacity="0.47"/>
<stop offset="1" stop-color="red"/>
</linearGradient>
</defs>
</svg>
</body>
</html>
推荐阅读
- mysql - mysql选择带有后备的行
- python - Rest API Google Cloud - 创建/编辑/列出 API 密钥
- scala - Http4s解码器如何自定义无效字段的错误消息
- mongodb - 如何将对象数组更改为mongodb中的数组?
- javascript - 更改同一组中两个单选按钮之间的间距
- node.js - 我们如何决定在项目中我们需要角色基础用户,或者我们创建每个用户模式,如买方卖方和代理 mongodb 和 nodejs
- python - 在这个 python pygame 代码中,我是否更新了矩形对象 .midbottom 的属性?
- java - 使用 Spring 时检测丢失的 bean
- javascript - 如何将它变成 React Hooks for useEffect()?
- python - 漏洞?remove() 应该从关联列表中删除吗?