【发布时间】:2016-07-23 14:52:30
【问题描述】:
鉴于下面的 SVG,我正在尝试使用 CSS 允许将鼠标悬停在 g#Main_Layer 中的 tspan.hovertext 分类元素上,以取消隐藏 #Hover_Panels 中不相关的 g 元素。见下文:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 20.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1280px"
height="1569.2px" viewBox="0 0 1280 1569.2" style="enable-background:new 0 0 1280 1569.2;" xml:space="preserve">
<style type="text/css">
text{font-family:'Lato';font-weight:300;}
#Hover_Text {
text-transform: uppercase;
}
.st0{fill:#404041;}
.st1{font-family:'Lato';font-weight:300;}
.st5{font-family:'Lato';font-weight:400;}
.st6{font-size:20px;}
.st7{fill:none;stroke:#5880AC;stroke-width:1.073;}
.st22{display:none;}
.st23{display:inline;fill:#016699;}
.st24{font-size:26.44px;}
.hovertext {
cursor: pointer;
}
.hovertext:hover {
font-weight: bold;
}
.hovertext:hover + #Hidden_Text {
display: block;
}
</style>
<g id="Main_Layer">
<text id="Hover_Text" transform="matrix(1 0 0 1 1044.0001 878.011)">
<tspan x="0" y="0" class="st4 st5 st6">hover </tspan>
<tspan x="0" y="180" class="hovertext st4 st1 st6">HOVER TEXT</tspan>
</text>
</g>
<g id="Hover_panels">
<g id="Default_Text" >
<text transform="matrix(1 0 0 1 459.2306 1051.639)">
<tspan x="0" y="0" class="st16 st1 st19">Default Text </tspan>
</text>
</g>
<g id="Hidden_Text" class="st22">
<text transform="matrix(1 0 0 1 566.0988 1163.5396)" class="st23 st1 st24">Hidden Text</text>
</g>
</g>
</svg>
问题是我不能完全控制 XML 布局(由我们的设计师提供的 Illustrator 生成),并且出于我希望我可以在这里讨论的原因,我们不能使用 Javascript 来实现这种效果。
当仅使用 CSS 时,如何在将鼠标悬停在 .hovertext 元素上时,将 display: block 添加到 #Hidden_Text 元素,并隐藏 #Default_Text 元素?
谢谢!
【问题讨论】:
-
您无法仅使用 CSS 来实现这一点 - 您可以在悬停时更改子元素的状态,而不是父元素或兄弟元素。