css - 之前元素的过渡效果

标签 css reactjs css-transitions

我正在尝试让“预约”按钮在该网站上工作 https://templates.hibootstrap.com/arrola/default/index-2.html 。我有以下CSS

.appointmentButton:before {
  content: '';
  position: absolute;
  top: 0;
  width: 100%;
  height: 100%;
  transform: scale(0);
  left: 0;
  right: 0;
  opacity: 0;
  z-index: -1;
  transition: all 0.5s;
}

.appointmentButton {
  padding: 10px 30px;
  color: white;
  text-align: center;
  position: relative;
  overflow: hidden;
  z-index: 0;
  text-transform: capitalize;
  transition: 0.5s;
  background-color: $black1;
  border: none;
  outline: none;
  text-decoration: none;
  &:hover:before {
    background-color: $greenColor;
    transform: scale(1);
    opacity: 1;
  }
}

和 html 元素: <a className={styles.appointmentButton} href="/appointment">Book an Apppointment</a> 。 我正在尝试将按钮背景颜色更改为绿色。

最佳答案

约会按钮添加显示:内联 block

.appointmentButton {
  padding: 10px 30px;
  color: white;
  text-align: center;
  position: relative;
  z-index: 1;
  overflow: hidden;
  text-transform: capitalize;
  transition: 0.5s;
  border: none;
  outline: none;
  text-decoration: none;
  background-color: #191f30;
  display: inline-block;
}
  .appointmentButton::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 100%;
    transform: scale(0);
    opacity: 0;
    transition: all 0.5s;
    background-color: #72ae44;
    z-index: -1;
  }
  
 .appointmentButton:hover::before {
    width: 100%;
    height: 100%;
    transform: scale(1);
    opacity: 1;
  }
<a class="appointmentButton" href="/appointment">Book an Apppointment</a>

关于css - 之前元素的过渡效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75281285/

相关文章:

reactjs - React, typescript 属性 'setState'在类型中丢失

css - 使用 CSS3 Transition 淡出然后淡入元素

html - 如何转换 z-index?

css - 站点网络栏 - 显示当前站点统计信息、CSS?

javascript - React 中使用 FileReader 的正确获取主体是什么

reactjs - React-query 重新获取 nextjs 中页面更改的数据

html - 在 x 属性上显示带有转换的隐藏 div

伪元素的 CSS 动画在 Chrome 和 IE 中有效,但在没有 "position: absolute"的情况下在 Safari 和 Firefox 中是静止的

css - bool 玛卡内容改变颜色

angularjs - 如何修复移动可移植设备元素触摸不工作?