好吧,我已经成功地将文本转换为不同的颜色,延迟时间为1秒,但是当鼠标不再悬停在元素上时,我无法弄清楚如何使其转换回原始颜色而不进行它立即。
我环顾四周,找不到多少帮助。如果我发现任何东西,我无法弄清楚如何将它拼凑在一起以使其正常工作。
HTML:
<div id="navbar">
<div id="navlinks">
<nav>
<ul id="navlist">
<li><a href="#">HOME</a></li>
<li><a href="#">ASSIGNMENTS</a></li>
<li><a href="#">DREAM CARS</a></li>
<li><a href="#">PROJECTS</a></li>
<li><a href="#">CONTACT</a></li>
</ul>
</nav>
</div>
</div>
CSS:
body{
margin:0 auto;
}
#logo{
margin:auto;
width:430px;
}
#navbar{
width:100%;
height:50px;
display:table;
margin:auto;
}
#navlinks ul {
display:table;
border-collapse:collapse;
width:100%;
margin:0 0 20px;
padding:0;
list-style:none;
}
#navlinks li {
display: table-cell;
vertical-align: middle;
text-align:center;
width:20%;
background: linear-gradient(to right, #111 50%, #444 50%);
background-size: 200% 100%;
background-position:left top;
transition:all 1s ease;
-webkit-transition-delay:all 1s ease;
-moz-transition-delay:all 1s ease;
-ms-transition-delay:all 1s ease;
-o-transition-delay:all 1s ease;
}
#navlinks li:hover{
background-position:right top;
}
#navlinks a {
text-decoration:none;
color: #999;
text-transform: uppercase;
display:block;
padding-top:10px;
padding-bottom:10px;
font: bold 12px/25px Arial, Helvetica;
}
#navlinks a:hover{
color:black;
transition:all 1s ease;
-webkit-transition-delay:all 1s ease;
-moz-transition-delay:all 1s ease;
-ms-transition-delay:all 1s ease;
-o-transition-delay:all 1s ease;
}
我也试图在这方面遵循jquery教程,它根本就没有对页面做任何事情。
答案 0 :(得分:11)
#navlinks a {
transition:color 1s ease;/*i just moved this from anchor*/
}
#navlinks li:hover a{
color:black;
}
body{
margin:0 auto;
}
#logo{
margin:auto;
width:430px;
}
#navbar{
width:100%;
height:50px;
display:table;
margin:auto;
}
#navlinks ul {
display:table;
border-collapse:collapse;
width:100%;
margin:0 0 20px;
padding:0;
list-style:none;
}
#navlinks li {
display: table-cell;
vertical-align: middle;
text-align:center;
width:20%;
background: linear-gradient(to right, #111 50%, #444 50%);
background-size: 200% 100%;
background-position:left top;
transition:all 1s ease;
}
#navlinks li:hover{
background-position:right top;
}
#navlinks a {
text-decoration:none;
color: #999;
text-transform: uppercase;
display:block;
padding-top:10px;
padding-bottom:10px;
font: bold 12px/25px Arial, Helvetica;
transition:color 1s ease-in-out;
}
#navlinks li:hover a{
color:black;
}
<div id="navbar">
<div id="navlinks">
<nav>
<ul id="navlist">
<li><a href="#">HOME</a></li>
<li><a href="#">ASSIGNMENTS</a></li>
<li><a href="#">DREAM CARS</a></li>
<li><a href="#">PROJECTS</a></li>
<li><a href="#">CONTACT</a></li>
</ul>
</nav>
</div>
</div>
答案 1 :(得分:0)
转换不应该在CSS中的悬停选择器中,而应该在没有任何修改状态的元素选择器中。
#navlinks a {
text-decoration:none;
color: #999;
text-transform: uppercase;
display:block;
padding-top:10px;
padding-bottom:10px;
font: bold 12px/25px Arial, Helvetica;
transition:all 1s ease;
-webkit-transition-delay:all 1s ease;
-moz-transition-delay:all 1s ease;
-ms-transition-delay:all 1s ease;
-o-transition-delay:all 1s ease;
}