我的网站侧边栏上的<ul>
中有一些导航元素。这是相关的标记和CSS样式:
<ul>
<li><a href="">Blog</a></li>
<li><a href="">Work</a></li>
<li><a href="">About</a></li>
<li><a href="">Contact</a></li>
</ul>
#sidebar ul {
list-style-type: none;
float: right;
position: relative;
right: -10px;
}
#sidebar ul li a {
display: inline-block;
line-height: 30px;
text-decoration: none;
padding: 0px 10px;
color: #555555;
}
#sidebar ul li a:hover {
background: url('images/nav-hover.png') no-repeat;
color: #f0f0f0;
}
当用户将鼠标悬停在导航元素(<a>
标记)上时,我希望背景nav-hover.png
使用CSS过渡从右侧滑入。我试过这个,但它似乎不起作用:
#sidebar ul li a {
background: none;
transition-property: background;
transition-duration: 1s;
display: inline-block;
line-height: 30px;
text-decoration: none;
padding: 0px 10px;
color: #555555;
}
#sidebar ul li a:hover {
background: url('images/nav-hover.png') no-repeat;
color: #f0f0f0;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
我怎样才能实现这一目标?
JSFiddle链接:http://jsfiddle.net/2EfYa/
答案 0 :(得分:0)
您需要转换background-position
:
http://jsfiddle.net/vQgEd/ - 可能仅适用于webkit
ul li a {
background: url('http://lorempixel.com/400/200') -100% 0px no-repeat;
transition: background-position 1s;
-webkit-transition: background-position 1s;
display: inline-block;
line-height: 30px;
text-decoration: none;
padding: 0px 10px;
color: #555555;
}
ul li a:hover {
background-position:left top;
color: #f0f0f0;
}