IE 中嵌套 ul li ul 间隙
我在 IE 中显示嵌套列表时遇到问题,firefox 显示完美。
我还附上了屏幕截图和代码。
HTML 代码:
<div class="header-boxes" id="topic-options">
<a id="slidertoggle" href="#">List Title</a>
<div id="options" style="display: none;">
<ul>
<li ><a href="#">Topic1</a></li>
<li ><a href="#">Topic2</a></li>
<li ><a href="#">List1 » </a>
<ul >
<li><a href="#">Topic3</a></li>
<li><a href="#">Topic4</a></li>
<li><a href="#">Topic5</a></li>
</ul>
</li>
<li ><a href="#">Topic6</a></li>
</ul>
</div>
</div>
CSS 代码:
#topic-options {
width: auto;
z-index: 3000;
}
.header-boxes {
float: left;
font-family: "Trebuchet MS",Arial,sans-serif;
font-size: 13px;
height: 27px;
margin-right: 8px;
}
a#slidertoggle {
background: url('2downarrow.png') no-repeat scroll 95% 50% #D9E4FF;
border-radius: 5px 5px 5px 5px;
color: #3F3019;
display: block;
padding: 7px;
width: auto;
margin: 0;
}
a:link, body_alink {
color: #B35400;
}
a {
color: #B35400;
text-decoration: none;
}
#options {
border: 1px solid #EBE1D6;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
display: none;
position: absolute;
width: auto;
z-index: 50;
}
ol, ul {
list-style: none outside none;
padding : 0;
margin : 0;
}
#options ul li {
border-bottom: 1px solid #EBE1D6;
background-color: #DFEFFC;
position: relative;
}
#options ul li a {
background-color: #DFEFFC;
display: block;
padding: 7px 10px;
}
#options ul ul {
border: 1px solid #EBE1D6;
border-bottom-right-radius: 5px;
border-top-right-radius: 5px;
left: 100%;
position: absolute;
top: -1px;
visibility: hidden;
}
ScreenShots:
在 Firefox 中,代码运行良好,并且可以按预期正常显示嵌套列表。
Firefox :
Firefox http://geniusguru.in/test/moz.jpg
在 IE 中(已测试在 IE7 中)代码显示如下图所示,li 内嵌套的 ul 与其父级之间有间隙。尝试了所有该死的东西,但没有运气。
IE7 :
IE7 http://geniusguru.in/test/ie.JPG
请帮助我。
抱歉没有发布我的 jquery 代码
JQUERY 代码:
function getSubnav(ele) {
if (ele.nodeName.toLowerCase() == 'li') {
var subnav = $('> ul', ele);
return subnav.length ? subnav[0] : null;
} else {
return ele;
}
}
$(document).ready(function(){
$('#slidertoggle').click(function(e){
e.preventDefault();
$('#options').show();
});
$('#options').mouseleave(function(e){
$('#options').hide();
});
var maxWidth = $('#topic-options').width()>$('#options').width()?$('#topic-options').width()+24:$('#options').width()+24;
$('#topic-options').css({'width': maxWidth+'px'});
$('#options').css({'width': maxWidth+'px'});
$('#options > ul > li > ul').each(function(){
$(this).css({'width' : maxWidth+'px'});
});
$('#options > ul > li').hover(function(){
var sub = getSubnav(this);
if(!sub) return;
$(sub).css({'visibility' : 'visible'});
},
function(){
var sub = getSubnav(this);
if(!sub) return;
$(sub).css({'visibility' : 'hidden'});
});
});
谢谢,
桑迪普
I have got a problem in displaying the nested list in IE, firefox displays it perfect.
I'm attaching the screenshots and code also.
HTML Code:
<div class="header-boxes" id="topic-options">
<a id="slidertoggle" href="#">List Title</a>
<div id="options" style="display: none;">
<ul>
<li ><a href="#">Topic1</a></li>
<li ><a href="#">Topic2</a></li>
<li ><a href="#">List1 » </a>
<ul >
<li><a href="#">Topic3</a></li>
<li><a href="#">Topic4</a></li>
<li><a href="#">Topic5</a></li>
</ul>
</li>
<li ><a href="#">Topic6</a></li>
</ul>
</div>
</div>
CSS Code :
#topic-options {
width: auto;
z-index: 3000;
}
.header-boxes {
float: left;
font-family: "Trebuchet MS",Arial,sans-serif;
font-size: 13px;
height: 27px;
margin-right: 8px;
}
a#slidertoggle {
background: url('2downarrow.png') no-repeat scroll 95% 50% #D9E4FF;
border-radius: 5px 5px 5px 5px;
color: #3F3019;
display: block;
padding: 7px;
width: auto;
margin: 0;
}
a:link, body_alink {
color: #B35400;
}
a {
color: #B35400;
text-decoration: none;
}
#options {
border: 1px solid #EBE1D6;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
display: none;
position: absolute;
width: auto;
z-index: 50;
}
ol, ul {
list-style: none outside none;
padding : 0;
margin : 0;
}
#options ul li {
border-bottom: 1px solid #EBE1D6;
background-color: #DFEFFC;
position: relative;
}
#options ul li a {
background-color: #DFEFFC;
display: block;
padding: 7px 10px;
}
#options ul ul {
border: 1px solid #EBE1D6;
border-bottom-right-radius: 5px;
border-top-right-radius: 5px;
left: 100%;
position: absolute;
top: -1px;
visibility: hidden;
}
ScreenShots :
In firefox the code works well and fine displaying the nested list as expected.
Firefox :
Firefox http://geniusguru.in/test/moz.jpg
In IE (tested in IE7) the code displays as the below image the nested ul inside li has a gap between it and its parent. Tried all the bloddy stuff but no luck.
IE7 :
IE7 http://geniusguru.in/test/ie.JPG
Please help me out.
Sorry for not posting my jquery code
JQUERY Code :
function getSubnav(ele) {
if (ele.nodeName.toLowerCase() == 'li') {
var subnav = $('> ul', ele);
return subnav.length ? subnav[0] : null;
} else {
return ele;
}
}
$(document).ready(function(){
$('#slidertoggle').click(function(e){
e.preventDefault();
$('#options').show();
});
$('#options').mouseleave(function(e){
$('#options').hide();
});
var maxWidth = $('#topic-options').width()>$('#options').width()?$('#topic-options').width()+24:$('#options').width()+24;
$('#topic-options').css({'width': maxWidth+'px'});
$('#options').css({'width': maxWidth+'px'});
$('#options > ul > li > ul').each(function(){
$(this).css({'width' : maxWidth+'px'});
});
$('#options > ul > li').hover(function(){
var sub = getSubnav(this);
if(!sub) return;
$(sub).css({'visibility' : 'visible'});
},
function(){
var sub = getSubnav(this);
if(!sub) return;
$(sub).css({'visibility' : 'hidden'});
});
});
Thanks,
Sandeep
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://jsfiddle.net/TEqmH/1/
在我这边工作正常,在 IE7 中,火狐等:/
http://jsfiddle.net/TEqmH/1/
Works fine on my end, both in IE7, firefox etc. :/