Nik*_*ins 1 css svg rect hover
所以我有一个巨大的 svg 文件,其中包含一个小矩形。我希望当您将鼠标悬停在该矩形上时它会改变颜色。我不能使用 onmouseover b/c,即 java,这是一个学校项目,我们被告知只能使用 html、html5、css 和 css3。我一直在尝试各种事情,但我不明白为什么它不起作用。我只添加了矩形 g 容器位。以及我正在使用的样式代码。我尝试将此样式代码添加到标头中,就在 svg 起始标记之后,添加到 g 容器中,添加到 rect 本身中(在本例中没有样式标记)。我可以添加整个 svg 文件,但那东西很大,所以我只会根据要求执行此操作。
<g
inkscape:groupmode="layer"
id="layer12"
inkscape:label="Hobitton Stadticon"
style="display:inline"
sodipodi:insensitive="true"
>
<style type="text/css">
<![CDATA[
.rect10023:hover {fill: #0000FF;}]]>
</style>
<rect
style="fill:#DF0101;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;"
id="rect10023"
width="8.2568808"
height="6.880734"
x="266.97247"
y="201.43393"
/>
<text
xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
x="343.72607"
y="-32.097607"
id="text10025"
sodipodi:linespacing="125%"
transform="matrix(0.72346735,0.6903586,-0.6903586,0.72346735,0,0)"
inkscape:transform-center-x="10.550459"
inkscape:transform-center-y="-7.7981651"><tspan
sodipodi:role="line"
id="tspan10027"
x="343.72607"
y="-32.097607"
style="font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Chiller;-inkscape-font-specification:Chiller">Hobbiton</tspan></text>
</g>
Run Code Online (Sandbox Code Playgroud)
1)矩形有一个id - 不是一个类,所以使用#rect10023:hover
2)您要么需要从内联样式中删除矩形的填充,要么
你需要fill: #0000FF!important;在你的课堂上使用