将列表的元素与容器元素的底部对齐

时间:2015-03-29 23:55:09

标签: html css

我需要将列表的元素对齐到容器的底部,这里是the fiddle

html

<nav id="access" role="navigation">
    <div class="menu-menu-1-container">
        <ul id="menu-menu-1" class="menu">
            <li>
                <img id="brand-img" src="http://nuclearpixel.com/content/icons/2010-02-09_stellar_icons_from_space_from_2005/earth_128.png">
            </li>
            <li id="menu-item-54" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-51 current_page_item menu-item-54"><a href="#">start</a>
            </li>
            <li id="menu-item-55" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-55"><a href="#">example</a>
            </li>
            <li id="menu-item-56" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-56"><a href="#">Example</a>
            </li>
        </ul>
    </div>
</nav>

CSS

#access {
    background: #222;
    /* Show a solid color for older browsers */
    background: -moz-linear-gradient(#252525, #0a0a0a);
    background: -o-linear-gradient(#252525, #0a0a0a);
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#252525), to(#0a0a0a));
    /* older webkit syntax */
    background: -webkit-linear-gradient(#252525, #0a0a0a);
    -webkit-box-shadow: rgba(0, 0, 0, 0.4) 0px 1px 2px;
    -moz-box-shadow: rgba(0, 0, 0, 0.4) 0px 1px 2px;
    box-shadow: rgba(0, 0, 0, 0.4) 0px 1px 2px;
    clear: both;
    display: block;
    float: left;
    margin: 0 auto 6px;
    width: 100%;
}
#access ul {
    font-size: 13px;
    list-style: none;
    margin: 0 0 0 0;
    padding-left: 0;
}
#access li {
    float: left;
    position: relative;
}
#access a {
    color: #eee;
    display: block;
    line-height: 3.333em;
    padding: 0 1.2125em;
    text-decoration: none;
}
#access ul ul {
    -moz-box-shadow: 0 3px 3px rgba(0, 0, 0, 0.2);
    -webkit-box-shadow: 0 3px 3px rgba(0, 0, 0, 0.2);
    box-shadow: 0 3px 3px rgba(0, 0, 0, 0.2);
    display: none;
    float: left;
    margin: 0;
    position: absolute;
    top: 3.333em;
    left: 0;
    width: 188px;
    z-index: 99999;
}
#access ul ul ul {
    left: 100%;
    top: 0;
}
#access ul ul a {
    background: #f9f9f9;
    border-bottom: 1px dotted #ddd;
    color: #444;
    font-size: 13px;
    font-weight: normal;
    height: auto;
    line-height: 1.4em;
    padding: 10px 10px;
    width: 168px;
}
#access li:hover > a, #access ul ul :hover > a, #access a:focus {
    background: #efefef;
}
#access li:hover > a, #access a:focus {
    background: #f9f9f9;
    /* Show a solid color for older browsers */
    background: -moz-linear-gradient(#f9f9f9, #e5e5e5);
    background: -o-linear-gradient(#f9f9f9, #e5e5e5);
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#f9f9f9), to(#e5e5e5));
    /* Older webkit syntax */
    background: -webkit-linear-gradient(#f9f9f9, #e5e5e5);
    color: #373737;
}
#access ul li:hover > ul {
    display: block;
}
#access .current-menu-item > a, #access .current-menu-ancestor > a, #access .current_page_item > a, #access .current_page_ancestor > a {
    font-weight: bold;
}

我在父div上尝试了table-cell,尝试了vertical-align:bottom,尝试了相对于父级的位置,等等没有任何效果,这就是我问这个问题的原因。

1 个答案:

答案 0 :(得分:1)

jsFiddle demo

#access {
    background: #222;
}
#access ul {
    list-style: none;
    margin: 0;
    padding-left: 0;
}
#access li {
    position: relative;
    display:inline-block;  /* instead of float-left */
    vertical-align:bottom; /* just to make sure */
}
#access a {
    color: #eee;
    text-decoration: none;
    display:inline-block;  /* instead of block */
    padding:1em;
}
#access li:hover > a, #access a:focus {
    background: #f9f9f9;
    color: #373737;
}

P.S:简化为CSS以消除噪音所需的东西。您将知道如何从这里开始