2011-03-30 67 views
0

任何人都可以帮助解决这个CSS问题。当NavLevel2文本长度超过200像素时,我需要NavDropDown变宽。列表项中应该没有文本换行,NavLevel1应该始终为200px宽。CSS列表问题

<div id="Nav"> 
    <ul> 
     <li class="NavLevel1" style="width: 200px; border: 1px solid Black;"><a><span>Level 1.1</span></a> 
      <ul id="NavDropDown" style="border: 1px solid Black;"> 
       <li class="NavLevel2"><a><span>Level 2.1.1 test to see if this will push the width out a little</span></a></li> 
       <li class="NavLevel2"><a><span>Level 2.1.2</span></a></li> 
       <li class="NavLevel2"><a><span>Level 2.1.3</span></a></li> 
      </ul> 
     </li> 
    </ul> 
</div> 
+0

请添加当前和预期结果的图片。 – 2011-03-30 20:58:21

回答

0

我贴到仓匆忙,刚找到我的解决方案。

<div id="Nav"> 
    <ul> 
     <li class="NavLevel1" style="width: 200px; border: 1px solid Black;"><a><span>Level 1.1</span></a> 
      <ul id="NavDropDown" style="border: 1px solid Black; position:absolute;"> 
       <li class="NavLevel2" style="white-space: nowrap;"><a><span>Level 2.1.1 test to see if this will push the width out a little</span></a></li> 
       <li class="NavLevel2"><a><span>Level 2.1.2</span></a></li> 
       <li class="NavLevel2"><a><span>Level 2.1.3</span></a></li> 
      </ul> 
     </li> 
    </ul> 
</div> 
1

width样式更改为min-width

+0

如果我这样做NavLevel1宽度延伸整个whoel页面。它需要保持200px; – theDawckta 2011-03-30 21:05:15

+0

你也可以设置一个'max-width'。可能你最好的选择是在'li'项目的内容周围使用''标签,这样内容就不会有中断,并且会将宽度拉大。试试看。 – RDL 2011-03-30 21:07:37