【问题标题】:React customize Material-UI Icons stylesReact 自定义 Material-UI 图标样式
【发布时间】:2020-07-16 08:34:20
【问题描述】:

我有一个带有 Typescript 的 React.js 应用程序。我想在锚标记上禁用已访问的 Material Icons 着色,并且我有以下样式表。

  const useStyles = makeStyles((theme: Theme) =>
    createStyles(
    myAnchor: {
      "&:visited": {color: "inherit"},
      "&:hover": {color: "inherit"},
      "&:active": {color: "inherit"}
    }
    ...
  )
  const classes = useStyles();

但是当我做<a className={classes.myAnchor}><FacebookIcon /></a>时它不起作用。 "&:visited" 有什么问题吗?

【问题讨论】:

  • @keikai 没有错误

标签: html css reactjs typescript material-ui


【解决方案1】:

您可以使用 Material-UI IconButtn

import React from "react";
import "./styles.css";
import { makeStyles, IconButton } from "@material-ui/core";
import FacebookIcon from "@material-ui/icons/Facebook";

const useStyles = makeStyles(theme => ({
  icon: {
    "& :visited": { color: "red" },
    "& :hover": { color: "red" },
    "& :active": { color: "red" }
  }
}));

export default function App() {
  const classes = useStyles();
  return (
    <div className="App">
      <IconButton
        className={classes.icon}
        // component={Link}
        // to={`/url`}
      >
        <FacebookIcon />
      </IconButton>
    </div>
  );
}

【讨论】:

  • 这不起作用,但它们之间有什么区别?
  • @tbraden 您能否更具体地说明什么不起作用?
  • 我突然想到这可能是我使用的materialui图标的问题,我会更新问题
  • 我认为真正起作用的是“&”后面的那个空格,所以&amp; :visited不是&amp;:visited
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-05-23
  • 1970-01-01
  • 1970-01-01
  • 2019-11-09
  • 2019-05-04
  • 1970-01-01
  • 2020-09-15
相关资源
最近更新 更多