【问题标题】:CSS transition not working because of a parent container DIV background property由于父容器 DIV 背景属性,CSS 转换不起作用
【发布时间】:2015-08-06 13:54:46
【问题描述】:

由于容器 DIV 的背景属性,我遇到了 CSS 转换无法正常工作的问题。这是我在网上找到的一段代码,但找不到我所在的页面,所以我不能回去问他们。它的本意是一个普通的按钮,但是当悬停在上面时,会滑出两个段落(一个在顶部,一个在底部)。它本身就可以正常工作,但是当我将其放入容器 DIV 并在容器上放置背景颜色时,它不再起作用。我对它进行了 Firebugged,发现当我禁用 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>

【问题讨论】:

    标签: html css css-transitions


    【解决方案1】:

    试试这样:Demo

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

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

    【讨论】:

    • 非常感谢您。我有一种感觉是 z-index,但在我试图解决这个问题时,我所做的只是显示两个段落而不悬停。 8-[) 非常感谢。
    • 哦..好的..所以我的回答帮助您解决了问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多