为 Font Awesome Stars 添加悬停效果

Add Hover effect to Font Awesome Stars

我想要一个简单的方法,将鼠标悬停在它们上面,它们就会变成纯黄色。

const styles = theme => ({
  root: {
    flexGrow: 1,
    overflow: 'hidden',
    padding: theme.spacing(0, 3),
  },
  paper: {
    maxWidth: 800,
    margin: `${theme.spacing(2)}px auto`,
    padding: theme.spacing(2),
  },
  textField: {
    marginLeft: theme.spacing(1),
    marginRight: theme.spacing(1),
    width: 200,
  },
  playButton: {
    display: "flex",
    flexDirection: "column",
    justifyContent: "center",
    alignItems: "center",
    position: "relative",
    "& .playButton": {
      position: "absolute",
      top: "60%",
      left: "-55px",
      transform: "translateY(-50%)",
    },
  }
});

function Tasks(props) {
  const { classes } = props;
  return (
    <div className={classes.root}>
      <Paper className={classes.paper}>
        <Grid container spacing={2}>
          <Grid item xs={12} sm container>
            <Grid item xs container direction="column" spacing={2}>
              <Grid item xs>
              <div className="name-label">
              Name
              </div>
              <Typography variant="h6" gutterBottom>
              {props.name}
              </Typography>
              <div className="form-divider"></div>
                <Typography variant="body2" color="textSecondary">
                {props.description}
                </Typography>
              </Grid>
            </Grid>
            <Grid item classes={{ root: props.classes.playButton}}>
    <Grid item xs={3} className="playButton">
      <i class="far fa-play-circle fa-2x"></i>
    </Grid>
    <div className="workers-assigned-label">
      Workers Assigned
    </div>
    <Typography variant="h6" gutterBottom>
        0/25
      </Typography>
      <div class="star-rating">
        <label class="far fa-star fa-2x"></label>
        <label class="far fa-star fa-2x"></label>
        <label class="far fa-star fa-2x"></label>
      </div>
    <div>
      unassigned
    </div>
  </Grid>
          </Grid>
        </Grid>
      </Paper>
    </div>
  );
}

export default withStyles(styles)(Tasks);

如果有人对如何让它们从 https://fontawesome.com/v4.7.0/icon/star-o 更改为中心填充黄色有任何建议,我们将不胜感激。最好使用 CSS 还是使用 React 来完成。

您检查过您使用的Font Awesome版本吗?这个图标好像是在4.7.0的。我遇到过多个图标未显示的问题,通常是因为我使用的是过时的版本,或者我想使用的图标位于较新版本的 Font Awesome 中。

如果您使用较新的版本,请检查此版本的图标是否仍然存在,它可能已被删除或重命名。

查看该特定字体的内容,您将使用的 2 个是 content: "\f006"content: "\f005"。 f005 是您想要变成黄色的实心星。

const styles = theme => ({
  playButton: {
    "& .rating": {
      
      "& .fa-star-o": {
        "&:hover": {
          "&::before": {
            content: "\f005",
            color: "yellow"
          }
        }
      }
      
    },
  },
});

并且就像其他人所说的那样,请确保包正常工作。