我在一些html中有这个SVG脚本:
<style type="text/css">
.Circle {
fill: #ff6666;
}
#bin {
fill: #fff;
}
.Line {
fill: #cccccc;
}
</style>
<g>
<circle class="Circle" id="OuterCircle" cx="15.8" cy="15.2" r="15.2" />
<path class="Path" id="bin" d="M9.6,7.6C9.2,7.8,9,8.3,9.1,8.6c0.1,0.3,0.4,0.5,0.5,0.5h12.5c0.4-0.2,0.6-0.6,0.5-1c-0.1-0.3-0.4-0.5-0.5-0.5h-9H9.6z" />
<path class="Path" id="bin" d="M13.9,6.7c-0.5,0.3-0.8,0.7-1,1c0.3,0,0.6,0,1,0c0-0.2,0-0.3,0-0.5h3.8c0,0.2,0,0.3,0,0.5c0.3,0,0.7,0,1,0c-0.2-0.3-0.5-0.7-1-1C16.6,6,15.1,5.9,13.9,6.7z" />
<path class="Path" id="bin" d="M9.6,9.6h12.5l-1,14.9c0,0-0.1,0.4-0.5,0.5c-0.2,0.1-0.4,0-0.5,0c-2.9,0-5.8,0-8.7,0c-0.1,0-0.3,0.1-0.5,0c-0.3-0.1-0.5-0.4-0.5-0.5C10.2,19.5,9.9,14.5,9.6,9.6z" />
<polygon class="Line" points="14.5,12 17.1,12 16.7,22.8 15,22.8 " />
<path class="Line" d="M18,12v10.8h1.7c0.3-3.8,0.6-7.5,0.9-11.3C19.8,11.7,18.9,11.8,18,12z" />
<path class="Line" d="M11,11.5c0.9,0.2,1.8,0.3,2.6,0.5v10.8h-1.7C11.9,22.8,11.9,22.8,11,11.5z" />
</g>
我正在尝试设置它,以便当您将鼠标悬停在“Path”类上时,它会更改“OuterCircle”类的样式。我到目前为止尝试过的CSS似乎没有用。
我目前悬停的当前CSS是:
.Circle:hover {
fill: #97D0FF;
}
g.Path:hover > #OuterCircle {
fill: #97D0FF;
}
我尝试过使用不同的同级组合器,但似乎没有任何效果,并且将circle属性置于path属性下会使svg图像混乱。我不太确定svg是如何工作的。
答案 0 :(得分:0)
没有以前的兄弟姐妹&#34; CSS中的选择器,因此您无法在#OuterCircle
上设置.Path:hover
样式。
但是,当群组悬停时,您可以将一个类添加到父组并添加样式#OuterCircle
。
.Circle {
fill: #ff6666;
}
#bin {
fill: #fff;
}
.Line {
fill: #cccccc;
}
g.icon:hover #OuterCircle {
fill: #97D0FF;
}
&#13;
<svg>
<g class="icon">
<circle class="Circle" id="OuterCircle" cx="15.8" cy="15.2" r="15.2" />
<path class="Path" id="bin" d="M9.6,7.6C9.2,7.8,9,8.3,9.1,8.6c0.1,0.3,0.4,0.5,0.5,0.5h12.5c0.4-0.2,0.6-0.6,0.5-1c-0.1-0.3-0.4-0.5-0.5-0.5h-9H9.6z" />
<path class="Path" id="bin" d="M13.9,6.7c-0.5,0.3-0.8,0.7-1,1c0.3,0,0.6,0,1,0c0-0.2,0-0.3,0-0.5h3.8c0,0.2,0,0.3,0,0.5c0.3,0,0.7,0,1,0c-0.2-0.3-0.5-0.7-1-1C16.6,6,15.1,5.9,13.9,6.7z" />
<path class="Path" id="bin" d="M9.6,9.6h12.5l-1,14.9c0,0-0.1,0.4-0.5,0.5c-0.2,0.1-0.4,0-0.5,0c-2.9,0-5.8,0-8.7,0c-0.1,0-0.3,0.1-0.5,0c-0.3-0.1-0.5-0.4-0.5-0.5C10.2,19.5,9.9,14.5,9.6,9.6z" />
<polygon class="Line" points="14.5,12 17.1,12 16.7,22.8 15,22.8 " />
<path class="Line" d="M18,12v10.8h1.7c0.3-3.8,0.6-7.5,0.9-11.3C19.8,11.7,18.9,11.8,18,12z" />
<path class="Line" d="M11,11.5c0.9,0.2,1.8,0.3,2.6,0.5v10.8h-1.7C11.9,22.8,11.9,22.8,11,11.5z" />
</g>
</svg>
&#13;