悬停下拉菜单超出容器宽度

时间:2014-12-24 23:19:56

标签: html css drop-down-menu containers

我有这个响应式的下拉菜单。当媒体查询开始并且我将鼠标悬停在我的链接上时,我的下拉菜单宽度会从我的容器中伸出。

  <!--   Navigation Menu    -->
    <div class="container">
        <div id="navigation">
            <label for="show-menu" class="show-menu">Menu</label>
            <input type="checkbox" id="show-menu" role="button">
            <ul id="menu">
                <li><a href="#">| Home</a></li>
                <li>
                    <a href="#">| SERMONS <span>&#x25BC</span></a>
                    <ul class="hidden">
                        <li><a href="#">Link 1</a></li>
                        <li><a href="#">Link 1</a></li>
                    </ul>
                </li>
                <li>
                    <a href="#">| EVENTS<span>&#x25BC</span></a>
                    <ul class="hidden">
                        <li><a href="#">slam Link 1</a></li>
                        <li><a href="#">Link 1</a></li>
                        <li><a href="#">LINK2</a></li>
                    </ul>
                </li>
                <li><a href="#">| CONNECT<span>&#x25BC</span></a></li>
                <li><a href="#">| STAFF<span>&#x25BC</span></a></li>
                <li><a href="#">| LOCATIONS <span>&#x25BC</span></a></li>
                <li><a href="#">| OTHERS</a></li>
            </ul>

        </div>
    </div>
    <!-- End of Navigation Menu    -->

这是css:

#navigation {
    background-color: @bg-color;
    height: 50px;
    margin: 0px auto;
}

/*Arrow down style */
#navigation span{
    font-size: 10px;
    padding-left: 4px;
    line-height: 50px;
}

/*Strip the ul of padding and list styling*/
ul {
    list-style-type:none;
    margin:0;
    padding:0;
    width: 100%;
    position: absolute;
}

/*Create a horizontal list with spacing*/
li {
    display:inline-block;
    float: left;
    margin-right: 1px;
    width:100px;

}

/*Style for menu links*/
li a {
    display:block;
    height: 50px;
    text-align: center;
    line-height: 50px;
    font-family:@Oswald;
    font-size: 16px;
    color: #fff;
    background: @bg-color;
    text-decoration: none;
}

/*Hover state for top level links*/
li:hover a {
    background: @light-gray;
}

/*Style for dropdown links*/
li:hover ul a {
    background: @light-gray;
    color: @white;
    height: 40px;
    line-height: 40px;
    width: 100%;
}

/*Hover state for dropdown links*/
li:hover ul a:hover {
    background: @bg-color;
    color: @white;
}

/*Hide dropdown links until they are needed*/
li ul {
    display: none;
    position: absolute;
    z-index: 100;
}

/*Make dropdown links vertical*/
li ul li {
    display: block;
    float: none;
}

/*Prevent text wrapping*/
li ul li a {
    width: auto;
    min-width: 100px;
    padding: 0 20px;
    text-align: left;
}


/*Display the dropdown on hover*/
ul li a:hover + .hidden, .hidden:hover {
    display: block;
    min-width: 100%;
}

/*Style 'show menu' label button and hide it by default*/
.show-menu {
    font-family:@Oswald;
    text-decoration: none;
    color: #fff;
    background: @bg-color;
    text-align: center;
    padding: 10px 0;
    display: none;
}

/*Hide checkbox*/
input[type=checkbox]{
    display: none;
}

/*Show menu when invisible checkbox is checked*/
input[type=checkbox]:checked ~ #menu{
    display: block;
}

input[type='text']{
    color: @bg-color;
}

/*Responsive Styles*/

@media screen and (max-width : 760px){
    /*Make dropdown links appear inline*/
    ul {
        position: static;
        display: none;
    }
    /*Create vertical spacing*/
    li {
        margin-bottom: 1px;
    }
    /*Make all menu links full width*/
    ul li, li a {
        width: 100%;
    }

    li ul li a {
        text-align: center;
    }
    /*Display 'show menu' link*/
    .show-menu {
        display:block;
    }

    .hide-tab {
        display: none;
    }

    #logo h1, #logo p {
        text-align: center;
    }


    #testr form {
        float: none;
    }

    #testr > form > input[type='text'] {
        margin: 0 auto; 
        width:60%;
        line-height: 60px;
    }    
}

我不知道如何解决它,因为我已经尝试了一切。一个简单的width:100%应该修复它,但它没有。

1 个答案:

答案 0 :(得分:-2)

我不知道你在哪里定义.container