将悬停效果添加到Font Awesome Stars

时间:2019-05-28 23:05:22

标签: css material-ui font-awesome

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

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来完成。

2 个答案:

答案 0 :(得分:2)

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

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

就像另一个人所说的那样,请确保该程序包正常工作。

答案 1 :(得分:1)

您是否检查了使用的Font Awesome的版本?该图标似乎在4.7.0中。我遇到了多个问题,无法显示图标,通常是因为我使用的版本过旧,或者我想使用的图标是在Font Awesome的较新版本中。

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