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

标签 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,在父 div 上尝试了 position relative,等等都没有用,这就是我问这个问题的原因。

最佳答案

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 以消除噪音所需的内容。你会知道如何从这里开始

关于html - 将列表的元素与容器元素的底部对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29336405/

相关文章:

html - 在页脚中上下对齐两个 div

javascript - JS - 不可破坏空间的转换 &nbsp

jquery - 将鼠标悬停在缩略图上会使用 CSS 更改更大的 div

css - 为什么我的下拉菜单在 ie7 中不起作用?

jquery - 你如何隐藏滚动条但允许滚动?

html - 有没有办法可以在不使用图像的情况下指定网站图标?

html - 标签 "for"和输入 "id"

CSS 不适用于浏览器,但它适用于 Eclipse

php - 如何在 css 样式表中使用 if/else 条件?在制作动态页面并通过 php 使用用户的值时

css - 根据帖子更改 tumblr 主题