【问题标题】:CSS classes has no effect for svg elementsCSS 类对 svg 元素没有影响
【发布时间】:2018-12-25 15:01:48
【问题描述】:

这是我的复制链接:https://stackblitz.com/edit/svgtest?file=style.css

我应用了两个 css 类:

 .section:hover {
  transform: scale(1.2);
}
.section {
  transition: all 1s;
  transform-origin: 50% 50%;
}

在那些 svg 元素上:

render() {

    return <g className="section"
      // onMouseOver={e => this.props.currentMounting.onMountingHoveredOver(e)}
      //onMouseOut={e => this.props.currentMounting.onMountingHoveredOut(e)}
      onClick={e => this.props.currentMounting.onMountingSelected(e.currentTarget.id)}
      opacity={this.props.currentMounting.opacity}
      style={{ fill: 'red' }}
      id={this.props.currentMounting.id}>
      <rect className={"section"} x="0" y="0" height="60" width="60" />
      <rect className={"section"} x="70" y="0" height="60" width="60" />
      <text  
       className="section" x="0" y="40" fill="#000" font-size="30">Facade</text>

    </g>
  }

.section 类被应用到浏览器中,但是在悬停时没有任何反应??

【问题讨论】:

  • 你到底想做什么?
  • 正如 css 所说:“当鼠标悬停在 svg 元素上时将其放大”

标签: html css reactjs svg


【解决方案1】:

您需要将 CSS 文件导入到组件中。

import './style.css';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-11
    • 2021-06-09
    • 2014-01-28
    相关资源
    最近更新 更多