css - 为 Font Awesome Stars 添加悬停效果

标签 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 个字体是 content: "\f006"content: "\f005"。 f005 是实心星星,您需要将其变成黄色。

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

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

关于css - 为 Font Awesome Stars 添加悬停效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56351100/

相关文章:

java - Android 字体很棒的方形而不是某些字符(仅限 KitKat)

javascript - 当必须使用后代选择器时

css - 我可以使用 CSS 编辑类幻灯片的背景吗?

html - 垂直和水平居中 - 响应式

javascript - ReactJS + Material-UI : How to alternate colors between Material-UI <Table/>'s <TableRow/>?

javascript - 如何用字体很棒的图标替换 dijit 树中的图标?

Html5 CSS 表格边框在 IE 11 中不可见

javascript - 在react.js中使用Enter键和 "@material-ui/core/Button"提交表单

css - 多行 <Li​​stItemText>

html - 我应该在网站的粘性页脚中使用什么 Font Awesome fa-icon-code css 类作为论坛链接?