Button CSS transition does not work inside a DIV

梦想与她 提交于 2019-12-13 06:50:15

问题


All right? I'm having problems with an effect on CSS. Everything works perfectly until I put the code inside another div, and has a background that is not transparent. Look at the example below:

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>

You see, if you remove the id="bg" effect functions normally. Can anyone help me?

Thank U!


回答1:


The problem is on the z-index of the :before and :after.

Try this:

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

Also increase the z-index on the text inside the button.



来源:https://stackoverflow.com/questions/29420962/button-css-transition-does-not-work-inside-a-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!