按钮悬停效果下方颜色变化

时间:2017-11-09 21:46:18

标签: css

如何将此按钮悬停效果从当前自上而下反转到下顶?



.btn-1 {
  position: relative;
  border-width: 2px;
  border-color: #4285f4;
  color: #4285f4;
  background-color: transparent;
}


.slide-btn, .slide-btn::after {
  -webkit-transition: all 0.3s;
	-moz-transition: all 0.3s;
  -o-transition: all 0.3s;
	transition: all 0.3s;
}

.slide-btn::before, .slide-btn::after {
  background: #4285f4;
  content: '';
  position: absolute;
  z-index: -1;
}

.btn-1::after {
  height: 0;
  left: 0;
  top: 0;
  width: 100%;
}

.btn-1:hover:after {
  height: 100%;
}

  <button class="btn-1 slide-btn">Button 1</button>
&#13;
&#13;
&#13;

玩了很长时间,例如改为.btn-1 :: after {height:100%; }和.btn-1 :: after {height:0; ... ...它给了我倒置效果,但反色。

2 个答案:

答案 0 :(得分:2)

在.btn-1 ::之后从上到下更改 https://jsfiddle.net/rp042h6j/

.btn-1::after {
  height: 0;
  left: 0;
  bottom: 0;
  width: 100%;
}

答案 1 :(得分:1)

.btn-1::aftertop更改为bottom

.btn-1 {
  position: relative;
  border-width: 2px;
  border-color: #4285f4;
  color: #4285f4;
  background-color: transparent;
}

.slide-btn,
.slide-btn::after {
  -webkit-transition: all 0.3s;
  -moz-transition: all 0.3s;
  -o-transition: all 0.3s;
  transition: all 0.3s;
}

.slide-btn::before,
.slide-btn::after {
  background: #4285f4;
  content: '';
  position: absolute;
  z-index: -1;
}

.btn-1::after {
  height: 0;
  left: 0;
  bottom: 0;
  width: 100%;
}

.btn-1:hover:after {
  height: 100%;
}
<button class="btn-1 slide-btn">Button 1</button>