【问题标题】:css submenu ul li problemscss submenu ul li 问题
【发布时间】:2013-03-19 00:19:52
【问题描述】:

我有一个使用 SuperFish 的菜单,但最后 2 个子菜单没有正确对齐。

这是我的 jsfiddle:http://jsfiddle.net/uP4bY/4/

我的 CSS 如下所示:

    /*  Header/Navigation   */
 div#Nav {
    background:transparent url(../Images/nav_Bg.png) no-repeat scroll top left;
    height:70px;
    width:980px;
    margin:0 auto;
    display:block;
    position:relative;
    z-index:2;
}
/*Level 1 or Parent / Destination*/
 div#Nav ul {
    padding-top:9px;
    display:inline;
    list-style-type:none;
    margin:0;
}
div#Nav ul li {
    background:transparent url(../Images/nav_li_Separator.png) no-repeat scroll center left;
    padding-left:8px;
    margin-left:8px;
    display:inline;
    position:relative;
}
div#Nav ul li.First {
    background:none;
    margin:0;
    padding:0;
}
/*Level 2 Treks*/
 div#Nav ul li ul {
    left:10px;
    position:absolute;
    top:26px;
    padding:0 !important;
    z-index:100;
    height:500px;
    float:left;
    list-style:outside;
    width:auto;
}
/*Level 3 Everest Region*/
 div#Nav ul li ul li ul {
    float: left;
    height: 500px;
    left: 50px;
    list-style: disc outside none;
    padding: 0 !important;
    position: absolute;
    top: 30px;
    width: auto;
    z-index: 100;
}
/*Level 5 Everest Base Camp*/
 div#Nav ul ul ul ul ul {
    float: left;
    height: 500px;
    left: 50px;
    list-style: disc outside none;
    padding: 0 !important;
    position: absolute;
    top: 60px;
    width: auto;
    z-index: 100;
}
div#Nav ul li ul li {
    border-top:1px solid #2f3b48;
    border-right:1px solid #384857;
    border-bottom:1px solid #384857;
    height:24px;
    display:block;
    padding:5px 15px 0;
    width:150px;
    /*width:150px;*/
    border-left:1px solid #384857;
    margin:0 !important;
    background:transparent url(http://www.kenticotemplates.net/themeforest/DreamTravel/Images/Nav_ul_li_Bg.png) repeat scroll top left !important;
}
div#Nav a, div#Nav a:link, div#Nav a:visited {
    color:#7f8b98;
}
div#Nav a:hover, div#Nav a.selected {
    color:#96b2cb !important;
    text-decoration:none;
}
div#Nav ul#Links, div#Nav ul.nav {
    float:left;
    text-transform:uppercase;
}
div#Nav ul.Lang {
    float:right;
}
div#Nav ul li {
    float:left;
}

我很确定我需要设置最后一个 ul li 的样式,但是当我这样做时,它会移动前一个 ul li。

更新:去掉空格后应该是这样的! http://i48.tinypic.com/1zfpxqf.png

【问题讨论】:

  • 你的小提琴不适合我(显示所有项目),并且你在
      上缺少引号。
  • 它并不意味着工作......只需要对齐子菜单UL的......
  • 在这种情况下使用> 选择器会更简洁,例如#Nav>ul>li>ul 等等。
  • 我明白了... @LinusCaldwell 那个选择器是做什么的?父子???
  • 是的,它是子选择器。 #Nav > ul 将只针对您的#nav 下的ul,而不是ul > li 内的下一个。阅读更多:css-tricks.com/child-and-sibling-selectors

标签: html css superfish


【解决方案1】:

问题的解决方案是她的小提琴:http://jsfiddle.net/7mvuw/

演示:http://jsfiddle.net/7mvuw/embedded/result/

注意:我已经改变了外观,但 html 结构是相同的,外观和感觉用于演示目的,您可以根据需要进行调整。

#access {
    background: #000;
    display: block;
    float: left;
    margin: 0 auto;
    width: 940px;
}
#access .menu-header,
div.menu {
    font-size: 13px;
    margin-left: 12px;
    width: 928px;
}
#access .menu-header ul,
div.menu ul {
    list-style: none;
    margin: 0;
}
#access .menu-header li,
div.menu li {
    float: left;
    position: relative;
}
#access a {
    color: #aaa;
    display: block;
    line-height: 38px;
    padding: 0 10px;
    text-decoration: none;
}
#access ul ul {
    box-shadow: 0px 3px 3px rgba(0,0,0,0.2);
    -moz-box-shadow: 0px 3px 3px rgba(0,0,0,0.2);
    -webkit-box-shadow: 0px 3px 3px rgba(0,0,0,0.2);
    display: none;
    position: absolute;
    top: 38px;
    left: 0;
    float: left;
    width: 180px;
    z-index: 99999;
    padding-left:0;
}
#access ul ul li {
    min-width: 180px;
}
#access ul ul ul {
    left: 100%;
    top: 0;
}
#access ul ul a {
    background: #333;
    line-height: 1em;
    padding: 10px;
    width: 160px;
    height: auto;
}
#access li:hover > a,
#access ul ul :hover > a {
    background: #333;
    color: #fff;
}
#access ul li:hover > ul {
    display: block;
}
#access ul li.current_page_item > a,
#access ul li.current-menu-ancestor > a,
#access ul li.current-menu-item > a,
#access ul li.current-menu-parent > a {
    color: #fff;
}

【讨论】:

  • 哇,非常感谢!非常干净的代码..我在你的例子中学到了很多东西。再次感谢你!你太棒了!
  • Dhan'yavāda bhā'ī, āpa apanē na'ē dōsta haiṁ
  • 嗨,priceCheaperton,你是第一个尝试在 SO 上用印地语与我交谈的人。很酷的人当然我会很高兴与你交朋友。非常感谢您的回应。我希望你的问题最终得到解决。
猜你喜欢
  • 2012-11-19
  • 2011-06-11
  • 2013-02-12
  • 1970-01-01
  • 2014-01-06
  • 2011-08-06
  • 2016-01-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多