【发布时间】:2014-04-20 12:45:47
【问题描述】:
我有一个使用 :hover 来改变颜色的 SVG。它仅在我将鼠标悬停在 SVG 的实体部分上时才有效,而不是透明部分。我想知道如何让 SVG 与悬停在整个 SVG 上的鼠标进行交互。这样做的目的是使 SVG 成为一个链接,并且该链接只能在 SVG 的某些部分上单击。我不只是想要一个解决这个特定实例的解决方案,而是一个适用于许多实例的解决方案(如果我想要 SVG 的不同部分可点击。)我的 SVG 中的元素直接连接到 CSS 并使用
编辑:SVG 位于对象标签中
SVG
<?xml-stylesheet type="text/css" href="svg.css" ?>
<svg xmlns:osb="http://www.openswatchbook.org/uri/2009/osb" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" id="svg3036" version="1.1" inkscape:version="0.48.2 r9819" width="58" height="58">
<g class="test">
<path d="M 8.1 32.8 C 7.1 30.1 0.3 -4.6 11.1 4.9 21.9 14.5 15.9 12.8 29 12.8 42.1 12.9 36.1 14.6 46.9 5.1 57.7 -4.5 50.9 30.3 49.9 32.9 48.9 35.6 37.6 54.8 29 54.7 20.4 54.6 9.1 35.4 8.1 32.8 z" id="path3119" inkscape:connector-curvature="0" sodipodi:nodetypes="zzzzzzz" class="wolf"/>
<path d="M 31.5 23.3 46.6 21" id="path5212" inkscape:connector-curvature="0" sodipodi:nodetypes="cc" class="eyes"/>
<path d="M 33 23 C 32.3 33.9 45 22 45.2 21" id="path5260" inkscape:connector-curvature="0" sodipodi:nodetypes="cc" class="eyes"/>
<path sodipodi:nodetypes="cc" inkscape:connector-curvature="0" id="path5262" d="M 26.5 23.3 11.4 21" class="eyes"/>
<path sodipodi:nodetypes="cc" inkscape:connector-curvature="0" id="path5264" d="M 25 23 C 25.7 33.9 13 22 12.8 21" class="eyes"/>
</g>
</svg>
CSS
.wolf{
fill: none;
fill-opacity: 0;
stroke-width: 3.672px;
stroke-linejoin: round;
} /*.wolf:hover {
stroke: #777777;
}*/
.eyes{
fill: none;
fill-opacity: 0;
stroke-width: 1.26708329px;
}
.test {
stroke: #5ff6ff;
} .test:hover {
stroke: #555555;
}
【问题讨论】:
-
把 :hover 放在 svg 元素上? (除非我遗漏了什么)
-
对不起,我忘记在对象标签中添加它
-
活的例子,jsfiddle什么的?
-
设置高度和宽度。
-
用包装 div 包围它并将鼠标悬停在上面?
标签: html css svg transparency clickable