MCFAN
MCFAN

Reputation: 23

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

I'm having a problem with a CSS transition not working because of a container DIV's background property. It's a piece of code that I found surfing the Web, but can't find the page I was on, so I can't go back and ask them. What it's meant to do, is be a normal button, but when hovered over, two Paragraphs slide out (one at the top, one at the bottom). It works just fine on its own, but when I put it into a container DIV, and put a background color on the container, it no longer works. I Firebugged it and found that when I disable the BG property, it works. The crazy thing is, is that the transition is on the margin, and nothing to do with a BG. Bear with me, this is my first question, and I'm going to attempt to insert the code right...

#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>

Upvotes: 2

Views: 542

Answers (1)

G.L.P
G.L.P

Reputation: 7207

Try like this: Demo

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

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

The <p> tag margin was having negative z-index value, that's why it was behind #container bg, now I changed that z-index value to positive and gave position for <a> with more z-index value, to show that to front

Upvotes: 1

Related Questions