当我尝试为带有一些菜单项背景的树形菜单设置圆角时,我遇到了这个问题。请在此处找到示例http://jsfiddle.net/ardeezstyle/WqGgh/。
HTML 代码
<div class="tree">
<ul>
<li>
<span>Menu One</span>
<ul>
<li>Sub Menu One</li>
<li>Sub Menu Two</li>
<li>Sub Menu Three</li>
</ul>
</li>
<li class="expanded">
<span>Menu Two</span>
<ul>
<li>Sub Menu One</li>
<li>Sub Menu Two</li>
<li>Sub Menu Three</li>
</ul>
</li>
<li>
<span>Menu Three</span>
<ul>
<li>Sub Menu One</li>
<li>Sub Menu Two</li>
<li>Sub Menu Three</li>
</ul>
</li>
<li>
<span>Menu Four</span>
<ul>
<li>Sub Menu One</li>
<li>Sub Menu Two</li>
<li>Sub Menu Three</li>
</ul>
</li>
</ul>
CSS 代码
.tree {
border: 1px solid #bababb;
border-radius:4px;
width: 300px;
}
.tree ul {
list-style:none;
padding:0;
margin:0;
}
.tree ul li span{
display: block;
padding: 5px 10px 5px 20px;
background:#f0f0f0;
border-top: 1px solid #bababb;
cursor:pointer;
}
.tree ul li:first-child span{
border-top: none;
}
.tree ul ul li{
display: block;
padding: 5px 10px 5px 20px;
border-top:1px solid #bababb;
}
.tree ul ul li.hover{
background: #f5f5f5;
}
.tree ul li ul{
display: none;
}
.tree ul li.expanded ul{
display: block;
}
.tree ul li.expanded span{
background: #e1e2e3;
}
JS代码
$(function(){
$('.tree ul li span').click(function(){
$('.tree ul li').removeClass('expanded');
$(this).parent('li').addClass('expanded');
});
$('.tree li').bind('mouseover', function(){
$(this).addClass('hover');
});
$('.tree li').bind('mouseout', function(){
$(this).removeClass('hover');
});
});
任何帮助,将不胜感激。