Reputation: 25
I am trying to get a divs background color to transition and nothing seems to work. I have tried researching on here and other sites but I've found nothing that works. Any help much appreciated.
Here is the CSS:
.nav a:hover
{
color:black;
background-color:white;
}
.nav
{
width:200px;
position:relative;
left:10px;
top:125px;
background-color:black;
font-size:1.4em;
font-family: "Trebuchet MS", "Lucida Grande", Tahoma, sans-serif;
text-align:center;
color:white;
text-decoration:none;
vertical-align:middle;
-webkit-transition: width 2s linear;
-moz-transition: width 2s linear;
transition: width 2s linear;
}
Upvotes: 0
Views: 7612
Reputation: 25
Thanks for the help guys. I just had width there as I was playing with other things to get it to work and forgot to change it. As you know it was putting the transition on .nav a rather than just .nav that really did. Cheers.
Upvotes: 0
Reputation: 6933
Here you are
.nav a{
color: white;
background-color: black;
-webkit-transition: all 0.4s linear;
-moz-transition: all 0.4s linear;
transition: all 0.4s linear;
}
.nav a:hover {
color: black;
background-color: white;
}
.nav {
width: 200px;
position: relative;
left: 10px;
top: 125px;
background-color: black;
font-size: 1.4em;
font-family: "Trebuchet MS", "Lucida Grande", Tahoma, sans-serif;
text-align: center;
color: white;
text-decoration: none;
vertical-align: middle;
}
<div class="nav">
<a href="#">Something</a>
</div>
Upvotes: 0
Reputation: 433
Here's a simple version of what you want to do that I've lifted from CSS-Tricks (http://css-tricks.com/almanac/properties/t/transition/).
http://jsfiddle.net/vp5hg339/1/
It uses CSS3 transition and ease.
nav {
height:100px;
width:100px;
transition: background-color 0.5s ease;
background-color: red;
}
nav:hover {
background-color: green;
}
Upvotes: 0
Reputation: 5803
I see two issues here:
1) You are defining your transitions on the .nav
element, but only changing the color of the a
element on hover
2) You are only specifying a transition of width, not background color
Here is what you are probably looking for:
.nav a {
-webkit-transition: all 2s linear;
-moz-transition: all 2s linear;
transition: all 2s linear;
}
.nav a:hover
{
color:black;
background-color:white;
}
.nav
{
width:200px;
position:relative;
left:10px;
top:125px;
background-color:black;
font-size:1.4em;
font-family: "Trebuchet MS", "Lucida Grande", Tahoma, sans-serif;
text-align:center;
color:white;
text-decoration:none;
vertical-align:middle;
}
Upvotes: 2