按钮 CSS 过渡在 DIV 中不起作用

Button CSS transition does not work inside a DIV

好吗?我在 CSS 上遇到问题。一切正常,直到我将代码放入另一个 div,并且背景不透明。看下面的例子:

body {
  background: #2ecc71;
  padding:0;
  margin:0;
}

#bg{
  background: #000;
}
.container-button {
  padding: 10em;
  margin: 0 auto;
  width: 1170px;
  text-align: center;
  display: block;
  overflow: hidden;
}

/* GENERAL BUTTON STYLING */
.btn-more-info{
  display:block;
  overflow: hidden;
  text-align: center;
  display: inline-block;
  float: left;
}
.btn-more-info a,
.btn-more-info a::after {
  -webkit-transition: all 0.3s;
 -moz-transition: all 0.3s;
  -o-transition: all 0.3s;
 transition: all 0.3s;
  test-ident: -9999px;
  text-decoration: none;
}

.btn-more-info a {
  background: none;
  border: 2px solid #fff;
  border-radius: 5px;
  color: #fff;
  display: block;
  font-size: 14px;
  font-weight: bold;
  padding: 20px 50px;
  position: relative;
  text-transform: uppercase;
}

.btn-more-info a::before,
.btn-more-info a::after {
  background: #fff;
  content: '';
  position: absolute;
  z-index: -1;
}

.btn-more-info a:hover {
  color: #2ecc71;
}

/* BUTTON EFFECT */
.btn-effect {
  overflow: hidden;
}

.btn-effect::after {
  /*background-color: #f00;*/
  height: 100%;
  left: -35%;
  top: 0;
  transform: skew(50deg);
  transition-duration: 0.6s;
  transform-origin: top left;
  width: 0;
}

.btn-effect:hover:after {
  height: 100%;
  width: 135%;
}






.btn-send{
  overflow: hidden;
  text-align: center;
  clear: both;
}
.btn-send a,
.btn-send a::after {
  -webkit-transition: all 0.3s;
 -moz-transition: all 0.3s;
  -o-transition: all 0.3s;
 transition: all 0.3s;
  test-ident: -9999px;
  text-decoration: none;
}

.btn-send a {
  background: none;
  border: 2px solid #353B4C;
  border-radius: 5px;
  color: #353B4C;
  display: inline-block;
  font-size: 14px;
  font-weight: bold;
  padding: 20px 50px;
  position: relative;
  text-transform: uppercase;
}

.btn-send a::before,
.btn-send a::after {
  background: #353B4C;
  content: '';
  position: absolute;
  z-index: -1;
}

.btn-send a:hover {
  color: #FFF;
}
<div id="bg">
<div class="container-button">
  <div class="btn-more-info">
    <a href="" class="btn-effect">Continue lendo</a>
  </div>
  <div class="btn-send">
    <a href="" class="btn-effect">Enviar mensagem</a>
  </div>
</div>
</div>

你看,去掉id="bg"效果就正常了。 谁能帮帮我?

谢谢你!

问题出在 :before 和 :after 的 z-index 上。

试试这个:

.btn-more-info a::before,
.btn-more-info a::after {
    background: #fff;
    content: '';
    position: absolute;
    z-index: 0;
}

同时增加按钮内文本的 z-index。