在悬停按钮上添加光泽效果的问题

时间:2021-04-07 08:53:11

标签: javascript html css

我曾经使用下面的 css 代码为按钮添加光泽效果:

Student

给元素添加闪耀类使闪耀效果从左到右。

但是现在我有了这些按钮,我找不到合适的解决方案来在不扭曲原始图形的情况下在悬停时添加光泽效果...

.answer-buttons:after {
    content: "";
    position: absolute;
    top: -7%;
    left: -120%;
    width: 100%;
    height: 110%;
    opacity: 0;
    transform: skew(-40deg);
    background: rgba(255, 255, 255, 0.5);
    background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.5) 77%, rgba(255, 255, 255, 0.9) 92%, rgba(255, 255, 255, 0.0) 100%);
    z-index: 10000;
}

.answer-buttons.shine:after {
    opacity: 1;
    left: 70%;
    transition-property: left, top, opacity;
    transition-duration: 0.7s, 0.7s, 0.15s;
    transition-timing-function: ease;
}
.answer-buttons-container {
  position: absolute;
  top: 87%;
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 15px;

  
}


/*.answer-buttons:after {
    content: "";
    position: absolute;
    top: -7%;
    left: -120%;
    width: 100%;
    height: 110%;
    opacity: 0;
    transform: skew(-40deg);
    background: rgba(255, 255, 255, 0.5);
    background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.5) 77%, rgba(255, 255, 255, 0.9) 92%, rgba(255, 255, 255, 0.0) 100%);
    z-index: 10000;
}

.answer-buttons.shine:after {
    opacity: 1;
    left: 70%;
    transition-property: left, top, opacity;
    transition-duration: 0.7s, 0.7s, 0.15s;
    transition-timing-function: ease;
}
*/


.answer-buttons {
  font-family: "Vazir";
  font-size: 1.2em;
  color: white;
  display: block;
  /*margin: 2em auto;*/
  height: 70px;
  background: cornflowerblue;
  border: none;
  position: relative;
  width: 180px;
  transition: all 0.2s ease-out;
  -webkit-transition: all 0.2s ease-out;
  box-shadow: 0 0 0.25em #333;
  cursor: pointer;
  outline: none;
}

.answer-buttons::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  border: 90px solid transparent;
  border-top-width: 0;
  border-bottom-width: 0;
  height: 100%;
  width: 0;
  z-index: -1;
  transition: all 0.1s ease-out;
  -webkit-transition: all 0.1s ease-out;
  border-left-color: cornflowerblue;
}

.answer-buttons::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  border: 90px solid transparent;
  border-top-width: 0;
  border-bottom-width: 0;
  height: 100%;
  width: 0;
  z-index: -1;
  transition: all 0.1s ease-out;
  -webkit-transition: all 0.1s ease-out;
  border-right-color: cornflowerblue;
}

.answer-buttons:active {
  -webkit-transform: scale(1.2, 0.8);
  z-index: 1;
}

.answer-buttons:active::before {
  border-top-width: 10px;
  border-bottom-width: 10px;
  border-radius: 0.2em;
  top: -10px;
  border-left-color: cornflowerblue;
}

.answer-buttons:active::after {
  border-top-width: 10px;
  border-bottom-width: 10px;
  border-radius: 0.2em;
  top: -10px;
  border-right-color: cornflowerblue;
}

:root {
  --red: #ff0053;
  --orange: #ff9900;
  --green: #7ebd00;
  --blue: #4b87f2;
}

.answer-buttons-container #red {
  background: var(--red);
}

.answer-buttons-container #red::before {
  border-left-color: var(--red);
}

.answer-buttons-container #red::after {
  border-right-color: var(--red);
}

.answer-buttons-container #red:active::before {
  border-left-color: var(--red);
}

.answer-buttons-container #red:active::after {
  border-right-color: var(--red);
}

/*** orange button ***/
.answer-buttons-container #orange {
  background: var(--orange);
}

.answer-buttons-container #orange::before {
  border-left-color: var(--orange);
}

.answer-buttons-container #orange::after {
  border-right-color: var(--orange);
}

.answer-buttons-container #orange:active::before {
  border-left-color: var(--orange);
}

.answer-buttons-container #orange:active::after {
  border-right-color: var(--orange);
}

/*** green button ***/
.answer-buttons-container #green {
  background: var(--green);
}

.answer-buttons-container #green::before {
  border-left-color: var(--green);
}

.answer-buttons-container #green::after {
  border-right-color: var(--green);
}

.answer-buttons-container #green:active::before {
  border-left-color: var(--green);
}

.answer-buttons-container #green:active::after {
  border-right-color: var(--green);
}

/*** blue button ***/
.answer-buttons-container #blue {
  background: var(--blue);
}

.answer-buttons-container #blue::before {
  border-left-color: var(--blue);
}

.answer-buttons-container #blue::after {
  border-right-color: var(--blue);
}

.answer-buttons-container #blue:active::before {
  border-left-color: var(--blue);
}

.answer-buttons-container #blue:active::after {
  border-right-color: var(--blue);
}

我认为用三国方法为这些按钮添加发光效果是不可能的,因为如果我们这样做,使用 <div class="answer-buttons-container"> <button class="answer-buttons" id="red">اصلا بلد نبودم</button> <button class="answer-buttons" id="orange">نسبتا بلد نبودم</button> <button class="answer-buttons" id="green">تا حدودی بلد بودم</button> <button class="answer-buttons" id="blue">کاملا بلد بودم</button> </div> 伪元素制作的点击效果将被破坏!!!

0 个答案:

没有答案
相关问题