【问题标题】:Problems Creating a Pure CSS Dropdown Submenu in Submenu在子菜单中创建纯 CSS 下拉子菜单的问题
【发布时间】:2012-07-11 18:08:38
【问题描述】:

您好,我想知道这是否可能。我有一个使用带有子菜单的 CSS 创建的水平菜单,它工作得很好。但是,我想让子菜单出现在已经出现的子菜单的右侧。

菜单如下:http://jsfiddle.net/dvpKx/39/

代码是:

/*First reset ul styles*/
    .nav,
    .nav ul,
    .nav li,
    .nav a {
        margin: 0;
        padding: 0;
        border: none;
        outline: none;
    }

/*Now add fixed width & height to the menu along with rounded corners and gradients*/
    .nav {
    height: 50px;
    width: inherit;
    margin: 10px;


    background: -webkit-linear-gradient(top, rgb(198,56,32) 0%, rgb(127,48,35) 100%);
    background: -moz-linear-gradient(top, rgba(198,56,32,1) 0%, rgb(127,48,35) 100%);
    background: -o-linear-gradient(top, rgb(198,56,32) 0%, rgb(127,48,35) 100%);
    background: -ms-linear-gradient(top, rgb(198,56,32) 0%, rgb(127,48,35) 100%);
    background: linear-gradient(top, rgb(198,56,32) 0%, rgb(127,48,35) 100%);

    -webkit-border-radius: 15px;
    -moz-border-radius: 5px;
    border-radius: 5px;


    }


/*Float links left to align links horizontally & position relative to align submenus properly*/

    .nav li {
    position: relative;
    list-style: none;
    float: left;
    display: block;
    height: 50px;
    }


/* 
Styling menu links -
font, color, padding, etc. Then a dark text shadow and a color transition to create a smooth effect when the color changes on hover state. To create the links separator add a border to the left and right and then we will remove the left border from the first link and the right border from the last link. For the hover state we will only change the text color.
 */

    .nav li a {

border-bottom: none;                    

        background: none;
        display: block;
        padding: 0 14px;
        margin: 6px 0;
        line-height: 32px;
        text-decoration: none;

        border-left: 1px solid #393942;
        border-right: 1px solid #4f5058;

        font-family: Verdana, sans-serif;
        font-weight: bold;
        font-size: 14px;

        color: #f3f3f3;
        text-shadow: 2px 3px 0px rgba(0,0,0,0.6);

        -webkit-transition: color .2s ease-in-out;
        -moz-transition: color .2s ease-in-out;
        -o-transition: color .2s ease-in-out;
        -ms-transition: color .2s ease-in-out;
        transition: color .2s ease-in-out;
    }

    .nav li:first-child a { border-left: none; }
    .nav li:last-child a{ border-right: none; }

    .nav li:hover > a { 
        color: rgb(114,163,45); 
        background: none;
        font-size: 18px;
    }

/* 
SUB MENU 1
We will start to position the sub menu 50px from the top and 0px from the left of the menu item and add bottom rounded corners. We will set the opacity to 0 and on hover state to 1 to create the fade in/out effect. For the slide down/up effect we need to set the list height to 0px when is hidden and to 36px on hover state.
 */

.nav ul {

    position:absolute;

    top: 50px;
    padding-left: 0px;

    opacity: 1;
    background: rgb(43,35,34);

    -webkit-border-radius: 0 0 5px 5px;
    -moz-border-radius: 0 0 5px 5px;
    border-radius: 0 0 5px 5px;

    -webkit-transition: opacity .25s ease .1s;
    -moz-transition: opacity .25s ease .1s;
    -o-transition: opacity .25s ease .1s;
    -ms-transition: opacity .25s ease .1s;
    transition: opacity .25s ease .1s;
}

.nav li:hover > ul { opacity: 1; }

/* Hiding submenu 1 */
.nav ul li {
    height: 0;
    overflow: hidden;
    padding: 0;

    -webkit-transition: height .25s ease .1s;
    -moz-transition: height .25s ease .1s;
    -o-transition: height .25s ease .1s;
    -ms-transition: height .25s ease .1s;
    transition: height .25s ease .1s;
}
/* When hovered over, show submenu 1 */ 
.nav li:hover > ul li {
    height: 46px;
    overflow: hidden;
    padding: 0;

    z-index: 8999;
}
/* Hiding submenu TWO */
.nav ul ul li {
    height: 0;
    overflow: hidden;
    padding: 0;

    -webkit-transition: height .25s ease .1s;
    -moz-transition: height .25s ease .1s;
    -o-transition: height .25s ease .1s;
    -ms-transition: height .25s ease .1s;
    transition: height .25s ease .1s;
}
/* When hovered over, show submenu 1 */ 
.nav li:hover > ul ul li {
    height: 80px;
    padding: 0;

    z-index: 9000;
}



/* Setting width of submenu to 100px & add a bottom border instead of left and right ones 
(also removing it from last link)   */

.nav ul li a {
    width: 250px;
    padding: 4px 0 4px 40px;
    margin: 0;


    border: none;
    border-bottom: 1px solid #343438;
}

.nav ul li:last-child a { border: none; }

【问题讨论】:

标签: css drop-down-menu menu navigation


【解决方案1】:

我会推荐 Suckerfish 下拉菜单(一个 CSS 解决方案)。

代码:http://www.htmldog.com/articles/suckerfish/dropdowns/(特别是多级下拉部分大约向下 1/2)。此外,示例链接显示在页面底部。

【讨论】:

  • Suckerfish 的 +1 儿子是一个不错的工具包,也可以通过键盘导航(对可访问性很重要)
  • 谢谢你,太好了!我还刚刚找到了另一个我在这里寻找的东西:red-team-design.com/css3-dropdown-menu,在我的示例中使用时看起来像这样:jsfiddle.net/bGj3z
  • @user1518633 - 很好的发现。与 Suckerfish 下拉列表的儿子非常相似的实现,但是您的链接也通过一些视觉效果很好地修饰了它。看起来很棒。
【解决方案2】:

你可以试试这个

.menus {
    width:100px;
    height:50px;
    border: 5px solid #000000;
    border-radius: 25px;
    text-align: center;
    line-height: 50px;
    color: black;
    background-color: #dcdcdd;
}
.submenus {
    margin-top:10px;
    display:none;
    width:100px;
    height:50px;
    border: 5px solid #000000;
    border-radius: 25px;
    text-align: center;
    line-height: 50px;
    color: black;
}
#menu1outer:hover #submenus1 {
    display: block;
}

希望对您有所帮助,您可以在此处查看示例: reformas integrales madrid

【讨论】:

    猜你喜欢
    • 2018-11-23
    • 1970-01-01
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 1970-01-01
    • 2015-11-08
    • 2013-09-03
    相关资源
    最近更新 更多