【问题标题】:Material UI CSS Animation for underline用于下划线的 Material UI CSS 动画
【发布时间】:2020-08-06 11:18:45
【问题描述】:

我一直在尝试在 Material-UI 中实现动画,其中标签的下划线从左向右移动。 到目前为止我写的代码是

const useStyles = makeStyles({
link: {
    padding: "1rem",
    color: "black",
    fontSize: "18px",
    fontWeight: "400",
    lineHeight: "24px",
    position: "relative",

    "&:before": {
      content: "''",
      position: "absolute",
      width: "0",
      height: "2px",
      bottom: "0",
      left: "0",
      backgroundColor: "#FFF",
      visibility: "hidden",
      transition: "all 0.3s ease-in-out",
    },
    "&:before:hover": {
      visibility: "visible",
      width: "100%"
    }
  }
}

function Tab(props) {
  const classes = useStyles();
  const {href} = props;
  const preventDefault = (event) => event.preventDefault();
  return (

    <Link href={href} onClick={preventDefault} className={classes.link}>
      <Typography variant="h6">{props.children}</Typography>
    </Link>
  );
}

当我运行此选项卡时,该选项卡将获得默认行为,而不是预期的行为

我使用this link 作为参考

【问题讨论】:

    标签: html css reactjs material-ui


    【解决方案1】:

    .test{
      color:red;
      position:relative;
      display:inline-block;
    }
    .test::before{
          content: "";
          position: absolute;
          width: 0;
          height: 2px;
          bottom: 0;
          left: 0;
          background-color: green;
          visibility: "hidden";
          transition: all 0.3s ease-in-out;
        
    }
    .test:hover::before{
      visibility: visible;
          width: 100%;
    }
    <div class="test">
    hover me
    </div>

    【讨论】:

    • 现在试试,我已经修改了
    • 你能不能再试一次,如果不行我就分享代码编辑器链接
    • 改了代码还是不行,能不能分享下你的编辑器链接
    猜你喜欢
    • 2021-06-05
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    • 2015-12-12
    • 2017-12-11
    • 1970-01-01
    相关资源
    最近更新 更多