CSS 由于父容器 DIV 背景,过渡不工作 属性

CSS transition not working because of a parent container DIV background property

由于容器 DIV 的背景 属性,我遇到了 CSS 转换不工作的问题。这是我在网上找到的一段代码,但是找不到我所在的页面,所以我不能回去问他们。它的目的是做一个普通按钮,但是当鼠标悬停在上面时,会滑出两个段落(一个在顶部,一个在底部)。它自己工作得很好,但是当我将它放入容器 DIV 并在容器上放置背景颜色时,它就不再工作了。我对它进行了 Firebug,发现当我禁用 BG 属性 时,它可以工作。疯狂的是,过渡是边缘的,与 BG 无关。请耐心等待,这是我的第一个问题,我将尝试正确插入代码...

#container
{
 background: #cf6;
 display: inline-block;
 height: 500px;
 margin: 0 auto;
 text-align: center;
 width: 700px
}

.download-button
{
 margin: 50px auto;
 width: 100px;
}

.download-button a
{
 background: #003f87;
 background: -moz-linear-gradient(top, #003f87 0%, #3063a5 100%);
 background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#003f87), color-stop(100%,#3063a5));
 background: -webkit-linear-gradient(top, #003f87 0%,#3063a5 100%);
 background: -o-linear-gradient(top, #003f87 0%,#3063a5 100%);
 background: -ms-linear-gradient(top, #003f87 0%,#3063a5 100%);
 background: linear-gradient(top, #003f87 0%,#3063a5 100%);
 filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#003f87', endColorstr='#3063a5',GradientType=0 );
 color: white;
 display: block;
 font: 17px/50px Helvetica, Verdana, sans-serif;
 height: 50px;
 text-align: center;
 text-decoration: none;
 text-transform: uppercase;
 width: 200px;
}

.download-button a, 
.download-button p
{
 -webkit-border-radius: 10px;
 -moz-border-radius: 10px;
 border-radius: 10px;
 -webkit-box-shadow: 2px 2px 8px rgba(0,0,0,0.2);
 -moz-box-shadow: 2px 2px 8px rgba(0,0,0,0.2);
 box-shadow: 2px 2px 8px rgba(0,0,0,0.2);
}

.download-button p
{
 background: #222;
 color: #fff;
 display: block;
 font: 12px/45px Helvetica, Verdana, sans-serif;
 height: 40px;
 margin: -50px 0 0 10px;
 position: absolute;
 text-align: center;
 -webkit-transition: margin 0.5s ease;
 -moz-transition: margin 0.5s ease;
 -o-transition: margin 0.5s ease;
 -ms-transition: margin 0.5s ease;
 transition: margin 0.5s ease;
 width: 180px; 
 z-index: -1;
}

.download-button:hover .bottom
{
 margin: -10px 0 0 10px;
}

.download-button:hover .top
{
 line-height: 35px;
 margin: -80px 0 0 10px;
}

.download-button a:active
{
 background: #003f87;
 background: -moz-linear-gradient(top,  #003f87 36%, #3063a5 100%);
 background: -webkit-gradient(linear, left top, left bottom, color-stop(36%,#003f87), color-stop(100%,#3063a5));
 background: -webkit-linear-gradient(top,  #003f87 36%,#3063a5 100%);
 background: -o-linear-gradient(top,  #003f87 36%,#3063a5 100%);
 background: -ms-linear-gradient(top,  #003f87 36%,#3063a5 100%);
 background: linear-gradient(top,  #003f87 36%,#3063a5 100%);
 filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#003f87', endColorstr='#3063a5',GradientType=0 );
}

.download-button:active .bottom
{
 margin: -20px 0 0 10px;
}

.download-button:active .top
{
 margin: -70px 0 0 10px;
}
<div id="container">

<div class="download-button">
 <a href="#">Download</a>
 <p class="top">click to begin</p>
 <p class="bottom">1.2MB .zip</p>
</div>

</div>

这样试试:Demo

.download-button a {
    z-index: 100;
    position:relative;
}

.download-button p {  
    z-index: 0;
}

<p> 标签边距具有 negative z-index 值,这就是它落后于 #container bg 的原因,现在我将 z-index 值更改为正值并且为 <a> 提供更多 z-index 的位置,以显示在前面