【问题标题】:Button CSS transition does not work inside a DIV按钮 CSS 过渡在 DIV 中不起作用
【发布时间】:2015-06-07 21:08:34
【问题描述】:

好吗?我在影响 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" 效果函数。 谁能帮帮我?

谢谢你!

【问题讨论】:

    标签: html css button transition effect


    【解决方案1】:

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

    试试这个:

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

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

    【讨论】:

    • 感谢您的帮助,问题确实出在 z-index 上。但是如果我让他覆盖 0 按钮的文字。已经解决了问题,留下:之前和之后:z-index -1 和:悬停 z-index: 1 并解决了:)
    猜你喜欢
    • 2015-12-01
    • 2012-09-27
    • 2013-10-22
    • 1970-01-01
    • 2014-05-29
    相关资源
    最近更新 更多