导航菜单 - 不适用于 IE
我设计了一个导航菜单,它在 Chrome 和 Firefox 上工作正常,但在 IE7 和 IE8 上似乎无法正常工作..如何解决这个问题?
注意:这不是下拉功能。
<div class="nav-block">
<ul id="nav">
<li><a class="active" href="/">Home</a></li>
<li>
<a href="/">Category</a>
<ul class='subnav'>
<li><a href='#'>One</a></li>
<li><a href='#'>One</a></li>
<li><a href='#'>One</a></li>
</ul>
</li>
<li>
<a href="/">Accounts</a>
<ul class='subnav'>
<li><a href='#'>One</a></li>
<li><a href='#'>One</a></li>
<li><a href='#'>One</a></li>
</ul>
</li>
<li><a href="/">Logout</a></li>
</ul>
</div>
CSS:
<style>
.nav-block{
background-color:black;
height: 45px;
}
#nav {
padding:12px;
list-style:none;
}
#nav li{
display:inline;
margin:0 1px 0 -1px;
padding:3px 15px;
float:left;
font-size:14px;
}
#nav a {
background-color:white;
color:#C51721;
padding:10px;
text-decoration: none;
}
#nav .subnav {
padding:0px;
list-style:none;
width:130px;
border-right: 2px solid black;
border-bottom: 2px solid black;
border-left: 2px solid black;
color:#000000;
margin-top:9px;
margin-left:-2px;
background-color:white;
}
#nav .subnav li {
padding:0px;
float: none;
width:100px;
color:#000000;
}
#nav .subnav li a {
padding:3px;
padding-left:10px;
display:block;
background-color:white;
color:#C51721;
text-decoration: none;
border-bottom:1px solid #DEDEDE;
}
</style>
如果代码可以改进,请告诉我。谢谢
I have designed a Navigation Menu, it work fine on Chrome and Firefox but it don't appear to work properly on IE7 and IE8.. how to fix this?
Note: it is not a dropdown functionality.
<div class="nav-block">
<ul id="nav">
<li><a class="active" href="/">Home</a></li>
<li>
<a href="/">Category</a>
<ul class='subnav'>
<li><a href='#'>One</a></li>
<li><a href='#'>One</a></li>
<li><a href='#'>One</a></li>
</ul>
</li>
<li>
<a href="/">Accounts</a>
<ul class='subnav'>
<li><a href='#'>One</a></li>
<li><a href='#'>One</a></li>
<li><a href='#'>One</a></li>
</ul>
</li>
<li><a href="/">Logout</a></li>
</ul>
</div>
CSS:
<style>
.nav-block{
background-color:black;
height: 45px;
}
#nav {
padding:12px;
list-style:none;
}
#nav li{
display:inline;
margin:0 1px 0 -1px;
padding:3px 15px;
float:left;
font-size:14px;
}
#nav a {
background-color:white;
color:#C51721;
padding:10px;
text-decoration: none;
}
#nav .subnav {
padding:0px;
list-style:none;
width:130px;
border-right: 2px solid black;
border-bottom: 2px solid black;
border-left: 2px solid black;
color:#000000;
margin-top:9px;
margin-left:-2px;
background-color:white;
}
#nav .subnav li {
padding:0px;
float: none;
width:100px;
color:#000000;
}
#nav .subnav li a {
padding:3px;
padding-left:10px;
display:block;
background-color:white;
color:#C51721;
text-decoration: none;
border-bottom:1px solid #DEDEDE;
}
</style>
If the code can be improved, let me know. thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当我测试它时,我遇到了相反的问题:IE7也是如此小的。
这似乎是因为li上有一些边距。为了使它们具有相同的高度,我使用了:
主要问题是您有一个内联元素(
),其中嵌套了一个块元素(
; )。
您应该通过将
更改为块元素来修复它。但是,您会遇到其他问题,因为您
不会占用所有宽度...
这应该会让您接近您想要的。
When I test it, I have the opposite issue : IE7 being too small.
It seems to be because of some margins on the li. To have them all of the same height, I used :
The main issue is that you have an inline element (
<li>
) with a block element nested inside it (<a>
).You should fix it by changing your
<li>
to a block element. But then, you'll have other issue, since you<a>
won't take all the width...This should get you close to what you want.
确保您通过 DOCTYPE 标记声明您正在编码的 HTML 版本。这将确保没有浏览器以怪异模式运行,这可能会改变您的网站的呈现方式(也可能使您的网站显示奇怪)。
另外,如果您还没有这样做,请考虑使用 CSS 重置来帮助减少浏览器不一致的情况。尝试 Eric Meyer 重置:http://meyerweb.com/eric/tools/css/reset/
Make sure you are declaring what version of HTML you're coding in through the DOCTYPE tag. This will make sure that no browsers run in quirks mode which could change the way your website is rendered (aka. it may make your website display weird).
Also, if you're not already doing this, consider using a css reset to help reduce browser inconsistencies. Try the Eric Meyer reset: http://meyerweb.com/eric/tools/css/reset/