html - .svg 中的 <g> 元素不会在 :hover (css) 上放大

标签 html css svg

我是编码新手,有一些我无法解决的问题,希望您能帮助我。 问题是:我已经从 Visio 绘图中导出了一个 svg 文件,现在我正试图缩放这个 svg 中的一个元素。 我在 css 内悬停时使用了 transform: scale(2) !important 命令,但元素(#shape72-136 - 这是左上角的矩形)有点振动而不是按比例放大.它也不会更改为所需的颜色。

希望你能帮帮我。

.st1 {fill:none;stroke:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.75}
    .st2 {fill:#00b050;font-family:Calibri;font-size:1.00001em}
    .st3 {fill:#ffffff;stroke:#00b050;stroke-linecap:round;stroke-linejoin:round;stroke-width:1}
    .st4 {fill:none;fill-rule:evenodd;font-size:12px;overflow:visible;stroke-linecap:square;stroke-miterlimit:3}

#shape72-136:hover {fill:blue !important; width: 400px; height: 100px; transform: scale(2) !important; animation-name: example; animation-duration: 4s; animation-iteration-count: infinite;}
@keyframes example {
0% {
filter: brightness(1);
filter: contrast(1);

}
50% {
filter: brightness(2);
filter: contrast(0.1);

}
100% {
filter: brightness(1);
filter: contrast(1);

 }
}

你可以修改代码: https://jsfiddle.net/pickle/kcuntLLz/

最佳答案

这是一种方法,将静态变换移动到 rect 元素上,然后指定 transform-origin 和 transform-b​​ox 以确保从 rect 中心进行缩放。

.st1 {fill:none;stroke:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.75}
		.st2 {fill:#00b050;font-family:Calibri;font-size:1.00001em}
		.st3 {fill:#ffffff;stroke:#00b050;stroke-linecap:round;stroke-linejoin:round;stroke-width:1}
		.st4 {fill:none;
    fill-rule:evenodd;
    font-size:12px;
    overflow:visible;
    stroke-linecap:square;
    stroke-miterlimit:3}
    
#shape73-138:hover {
  fill: blue !important; 
  transform: scale(1.5); 
  /*animation-name: example;*/
  animation-duration: 4s;
  animation-iteration-count: infinite;
}
		
#shape73-138 {
  transform-origin: center center;
  transform-box: fill-box;
}

@keyframes example {
  0% {
    filter: brightness(1);
    filter: contrast(1);
	
  }
  50% {
    filter: brightness(2);
    filter: contrast(0.1);
	
  }
  100% {
    filter: brightness(1);
    filter: contrast(1);
	
  }
}
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" width="9.90261in" height="2.57908in" viewBox="0 0 712.988 185.694" xml:space="preserve" color-interpolation-filters="sRGB" class="st4">
    
    <g>
        <g id="shape73-138">
            <title>Rechteck.69</title>
            <rect transform="translate(48.5326,-103.539)" x="0" y="143.174" width="20.1861" height="42.5197" class="st3"/>
        </g>
    </g>
</svg>

关于html - .svg 中的 <g> 元素不会在 :hover (css) 上放大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47282027/

相关文章:

html - 垂直对齐一些字体

android - 如何访问或翻译 Vector Drawables 中的文本

javascript - 在不同的div中显示不同的网页

html - 无效对齐属性 HTML

javascript - 如何使用 ES6 以 Angular 编写特定于 Controller /页面的 LESS

java - 从 Jasper Reports 生成的 PDF 中的 SVG 标记

html - 如何缩放我的 SVG 以适应 d3 中其容器 div 的大小?

html - 如何将表单的复选框分组到 Node 中的数组中?

html - <ul> 背景颜色不起作用。我正在尝试为我的页面面包屑添加背景

css - IE 7 和 8 背景图像位置问题