我一直在努力让我的纯 CSS 菜单在所有版本的 IE 中工作,我想我几乎已经把它弄下来了,除了 IE7。
在有问题的网站上,我使用以下 CSS:
.header-bar {
position:fixed;
top: 0;
left: 0;
right: 0;
padding: 0;
background: #333;
font-size: 1.2em;
font-weight: bold;
z-index: 1000;
}
.header-bar a:hover {
text-decoration: none;
}
.header-bar a {
display: inline-block;
padding: 7px 10px 7px 10px;
color: #2C8FAA;
font-size:1.1em;
}
.header-bar ul {
list-style-type: none;
display: inline-block;
position: relative;
height: auto;
}
.header-bar ul li {
background: #333;
}
.header-bar ul li:hover {
background: #444;
color: #34AACB;
}
.header-bar ul.nav > li {
display: inline-block;
}
.header-bar ul ul {
display: none;
}
.header-bar ul ul li {
border-top: 1px solid black;
}
.header-bar ul li:hover > ul {
margin: 0;
display: block;
position: absolute; /* overrides other settings */
/* top: 28px; */
height: 28px;
min-width: 200px;
}
.header-bar ul ul li:hover ul {
top: 0; /* match position of parent, which should be position: relative; */
position: absolute;
margin-left: 199px; /* 150px min-width -1 px border */
border-left: 1px solid black;
}
.header-bar ul li a {
display: block;
}
.header-bar ul li ul li {
position: relative;
}
.header-bar ul ul li:hover ul ul {
position: absolute;
top: -48px; /* 28 + 1 for border */
margin-left: 199px; /* 150px min-width -1 px border */
border-left: 1px solid black;
}
.header-bar ul ul li:hover ul ul {
top: 0;
}
要设置如下所示的 HTML 样式:
<div class="header-bar">
<div class="container">
<ul class="nav">
<li>
<a href="#">Menu Item 1</a>
<ul>
<li>
<a href="#">Menu Item 1, Submenu 1</a>
<ul>
<li><a href="#">Menu Item 1, Submenu 1, Sub-submenu 1</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
这似乎适用于子菜单,但父菜单项似乎采用块布局,而不是inline-block
. 在这一点上,我已经束手无策,试图与 IE 作斗争,并且希望能多看几双眼睛。