html - 浏览器中的SVG是否支持CSS中重载的rotate()方法rotate(angle, centerX, centerY)?

标签 html css svg

我读过一个旋转变换,该变换支持使用 rotate(angle, centerX, centerY) 围绕中心点旋转,但它在通过 CSS 应用时似乎不起作用。

它作为一个属性内联工作:

<svg>
  <circle cx="50" cy="50" r="3" style="fill: black"/>

  <g id="arrow" style="stroke: black">
     <line x1="60" y1="50" x2="90" y2="50"/>
     <polygon points="90, 50, 85 45, 85, 55"/>
  </g>

  <use xlink:href="#arrow" transform="rotate(60, 50, 50)"/>
</svg>

但是通过 CSS 样式规则应用时它不起作用:

#arrow2 {
  transform: rotate(60, 50, 50);
}
<svg>
  <circle cx="50" cy="50" r="3" style="fill: black"/>

  <g id="arrow" style="stroke: black">
     <line x1="60" y1="50" x2="90" y2="50"/>
     <polygon points="90, 50, 85 45, 85, 55"/>
  </g>

  <g id="arrow2" style="stroke: red">
     <line x1="60" y1="50" x2="90" y2="50"/>
     <polygon points="90, 50, 85 45, 85, 55"/>
  </g>
</svg>

CSS

最佳答案

CSS 和 SVG 的“transform”属性不同。在这种情况下,试试这个:

#arrow2 {
  transform: rotate(60deg);
  transform-origin: 50px 50px;
}
<svg>
  <circle cx="50" cy="50" r="3" style="fill: black"/>

  <g id="arrow" style="stroke: black">
     <line x1="60" y1="50" x2="90" y2="50"/>
     <polygon points="90, 50, 85 45, 85, 55"/>
  </g>

  <g id="arrow2" style="stroke: red">
     <line x1="60" y1="50" x2="90" y2="50"/>
     <polygon points="90, 50, 85 45, 85, 55"/>
  </g>
</svg>

关于html - 浏览器中的SVG是否支持CSS中重载的rotate()方法rotate(angle, centerX, centerY)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57465645/

相关文章:

css - Sass嵌套扩展内部是自己的父级

javascript - SVG 平移和缩放不起作用

html - 在浏览器中查看扩展名为 .asp 的本地 html 文件

java - 在 HTML 中使用 Java applet 方法

javascript - 如何创建旋转木马 div Bootstrap

javascript - React 组件提示 SVG 渐变样式?

jquery - 如何获得对象附加的 svg?

javascript - 在运行时更新 CSS 文件,更改字体大小、背景颜色和窗口大小

javascript - 自定义 jQuery Accordion 样式和图像不起作用

javascript - 在您自己的网站上共享带有缩略图的链接