2013-10-19 64 views
0

我试图按照this example,但我不能让它为我的需要工作,一些帮助,将不胜感激。如何设计一个CSS子菜单?

UPDATE: 好吧,我的子菜单更好地感谢yourkishore和我解决了一点点怎么现在处理嵌套菜单,但在我的文本的底部我的子菜单仍然会出现吗?

** Updated jsFiddle **

HTML:

<ul id="menubar"> 
    <div id="title">title</div> 
    <li>File 
     <ul> 
     <li>Photoshop CC</li> 
     <li>Illustrator CC Adobe</li> 
     <li>My Web Design 
      <ul> 
      <li>HTML</li> 
      <li>CSS</li> 
      </ul> 
     </li> 
     </ul> 
    </li> 
    <li>Config</li> 
</ul> 
<div id=other></div> 

CSS

html, body {height:100%;width:100%;margin:0;} 
#menubar { 
    background: #eeeeee; 
    height:25%; 
    list-style-type: none; 
    width:100%; 
    display: inline-table; 
    margin:0; 
    padding:0; 
    z-index:99; 
} 
#menubar #title { 
    display:inline-block; 
    padding:0 5%; 
    font-size:140%; 
    font-weight:bold; 
    float:left; 
    height:100%; 
    display: inline-flex; 
    align-items: center; 
} 
#menubar li { 
    height:100%; 
    position:relative; 
    float:left; 
    padding:0 1%; 
    list-style-type: none; 
    white-space:nowrap; 
    display: inline-flex; 
    align-items: center; 
} 
#menubar li:hover { 
    background-color:#7faddb; 
} 
#menubar li > ul { 
    background-color:white; 
    z-index:99; 
    display: none; 
    position:absolute; 
    list-style-type: none; 
    margin:0; 
    padding:0; 
} 
#menubar li:hover > ul { 
    display: block; 
} 
#other { 
    background-color:green; 
    position:absolute; 
    top:25%; 
    bottom:0; 
    left:0; 
    right:0; 
} 

回答

0

它正常工作,在你的小提琴,使用HTML

<div id="title">title</div> 
<nav> 
<ul> 
    <li>File 
     <ul> 
     <li>Photoshop CC</li> 
     <li>Illustrator CC Adobe</li> 
     <li>My Web Design 
      <ul> 
      <li>HTML</li> 
      <li>CSS</li> 
      </ul> 
     </li> 
     </ul> 
    </li> 
    <li>Config</li> 
</ul> 
</nav> 
<div id=other></div> 

,并使用这个CSS

body, div, h1, h2, h3, h4, h5, h6, p, ul, ol, li, dl, dt, dd, img, form, fieldset, input, textarea, blockquote { 
    margin: 0; padding: 0; border: 0; 
} 

body { 

    font-family: Helvetica, sans-serif; font-size: 18px; line-height: 24px; 
} 

nav { 

    text-align: center; 
} 

nav ul ul { 
    display: none; 
} 

    nav ul li:hover > ul { 
     display: block; 
    } 


nav ul { 
    padding: 0 20px; 

    list-style: none; 
    position: relative; 
    display: inline-table; 
} 
    nav ul:after { 
     content: ""; clear: both; display: block; 
    } 

    nav ul li { 
     float: left; 
    padding:12px; 
    } 
     nav ul li:hover { 
      background: #505050; 

     } 
      nav ul li:hover a { 
       color: #171717; 
      } 

     nav ul li a { 
      display: block; padding: 25px 40px; 
      color: #994411; text-decoration: none; 
     } 


    nav ul ul { 
     background: #888888; border-radius: 0px; padding: 0; 
     position: absolute; top: 100%; 
    } 
     nav ul ul li { 
      float: none; 
      border-top: 1px solid #111; 
      border-bottom: 1px solid #575f6a; position: relative; 
     } 
      nav ul ul li a { 
       padding: 1px 40px; 
       color: #666; 
      } 
       nav ul ul li a:hover { 
        background: #333; 
       } 

    nav ul ul ul { 
     position: absolute; left: 100%; top:0; 
    } 
     #other { 
    background-color:green; 
    position:absolute; 
    top:25%; 
    bottom:0; 
    left:0; 
    right:0; 
    z-index:-1; 
} 
+0

我不知道如何适合我的菜单栏。我还是很新的:) – shuji

+0

根据你的menubar.try改变了HTML和CSS。 –

1

它显示在菜单内部,因为它们在里面。当你将鼠标移到外面时,让它们出现在外面。你需要设置一个名为position的属性。

为#menubar里你需要添加poistion:相对

,然后#menubar李UL需要添加现在的位置是:绝对的。

菜单总是在这个重要的属性上工作。没有这个,没有嵌套列表的菜单。只要学习CSS定位。祝一切顺利。

+0

非常感谢您的帮助,解决了一些问题,但我仍然一团糟。 – shuji

+0

如果您对网页开发未来不了解任何内容,请发送邮件给我。 – yourkishore