1

我一直在争取让所有版本的IE浏览器都能运行我的CSS菜单,而且我认为我几乎已经将它取下来了,IE7除外。CSS Only菜单,IE7问题

the site in question,我使用了下面的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打交道,并且会感激一双额外的双眼。

回答

2

尝试正常关闭您的li标签:

<div id="header-bar"> 
    <div class="container"> 
    <ul class="nav"> 
     <li><a href="#">Menu Item 1</a></li> 
     <ul> 
      <li><a href="#">Menu Item 1, Submenu 1</a></li> 
      <ul> 
       <li><a href="#">Menu Item 1, Submenu 1, Sub-submenu 1</a></li> 
      </ul> 
     </ul> 
    </ul> 
    </div> 
</div> 

- 编辑 -

使用这个在你的CSS:

.header-bar ul.nav > li { 
     display: inline-block; 
     *float:left 
} 

应该做的伎俩。

+0

谢谢,我在示例中缺少一个(并已修复它),但生产中并非如此。 – 2013-03-05 10:24:03

+1

另外你的html引用了'header-bar'和你的css到'.header-bar' – otinanai 2013-03-05 10:35:28

+1

请看看我的答案编辑。 – otinanai 2013-03-05 10:43:03

1

有几件事。

  1. <LI>标签没有正确关闭。
  2. 不支持display: inline-block;

要做到:

  1. 关闭所有<li>标签正确。
  2. 使用此CSS:

    .header-bar ul.nav > li { 
        display: inline-block; 
        *display: inline; 
        *zoom: 1; 
    } 
    

验证问题

如果还是你真的担心没有一个黑客,你可以做到这一点。使用保罗爱尔兰的条件HTML类是这样的:

<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]--> 
<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]--> 
<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]--> 
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]--> 
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]--> 

并在CSS,你可以给这个:

.ie6 .header-bar ul.nav > li, 
.ie7 .header-bar ul.nav > li { 
    display: inline; 
    zoom: 1; 
} 

现在你的HTML和CSS都是有效