繁体   English   中英

Svg悬停矩形改变颜色

[英]Svg hover rect change color

所以我有这个巨大的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>

1)rect有一个id - 而不是一个类,所以使用#rect10023:hover

2)您需要从内联样式OR中删除rect的填充

你需要使用fill: #0000FF!important; 在你的班上

这是因为您使用内联样式定义了矩形的填充,并且您正在为类设置样式而不是ID。 改变. #和删除fill:#DF0101; 和悬停工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM