gpt4 book ai didi

css - 在悬停链接时更改单独 SVG 多边形的填充

转载 作者:行者123 更新时间:2023-11-28 10:15:22 24 4
gpt4 key购买 nike

我在左栏中有一个房间列表,在右栏中有一个 SVG 平面图。我有两个问题:

当左栏中的链接使用纯 CSS 滚动时,有没有办法改变平面图中房间的颜色?

如果答案是否定的,我应该采取什么方法?我猜是某种 JS,但不知道从哪里开始或要搜索什么。

这是我到目前为止所做的工作示例:

div#list {float:left; width:50%}
div#list ul li a {color:#333}
div#list ul li a:hover {color:#ED5D45}
div#map {float:right; width:50%}
div#map svg#plan polygon.building {fill:#CCC}
div#map svg#plan a polygon.studio-j {fill:#333}
div#map svg#plan a:hover polygon.studio-j {fill:#ED5D45}
<div id="list">
<ul>
<li class="j"><a href="/studios/j/">Studio J</a></li>
</ul>
</div>
<div id="map">
<svg id="plan" x="0" y="0" viewBox="0 0 412 408" enable-background="new 0 0 412 408" xml:space="preserve">
<polygon class="building" points="0,68.1 377.2,0 411,407.3 20,405.7 "/>
<a xlink:href="/studios/j/" xlink:title="Studio J">
<polygon class="studio-j" points="214,126 261,126 261,131 388,131 377.2,0.4 213.5,30.2 "/>
</a>
</svg>
</div>

在这里 fiddle :https://jsfiddle.net/morgyface/7utpx1n6/

最佳答案

由于链接与 SVG 无关,因此在给定结构的情况下使用 CSS 是不可能的。

需要 JS 来简化问题。

或者,只需将链接放在 #map div 中(没有列表结构)并相应地调整 CSS。

a:hover {
color: red
}
div#map {
float: right;
width: 50%
}
div#map svg#plan polygon.building {
fill: #CCC
}
svg#plan a polygon.studio-j {
fill: #333
}
svg#plan a:hover polygon.studio-j {
fill: #ED5D45
}
.j:hover + svg#plan a polygon.studio-j {
fill: green;
}
<div id="map">
<a class="j" href="/studios/j/">Studio J</a>

<svg id="plan" x="0" y="0" viewBox="0 0 412 408" enable-background="new 0 0 412 408" xml:space="preserve">
<polygon class="building" points="0,68.1 377.2,0 411,407.3 20,405.7 " />
<a xlink:href="/studios/j/" xlink:title="Studio J">
<polygon class="studio-j" points="214,126 261,126 261,131 388,131 377.2,0.4 213.5,30.2 " />
</a>

</svg>
</div>

关于css - 在悬停链接时更改单独 SVG 多边形的填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29823169/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com