將列表的元素與容器元素的底部對齊

[英]Align the elements of a list to the bottom of the container element


I need to align the elements of a list to the bottom of the container, here its the fiddle

我需要將列表的元素對齊到容器的底部,這里是小提琴

The html

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

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;
}

I tried table-cell on the parent div, tried vertical-align:bottom, tried position relative on the parent, etc nothing worked really that's why I'm asking the question.

我在父div上嘗試了table-cell,嘗試了vertical-align:bottom,嘗試了相對於父級的位置,等等沒有任何效果,這就是我問這個問題的原因。

1 个解决方案

#1


1  

jsFiddle demo

jsFiddle演示

#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: simplified to CSS to the needed stuff to remove noise. You'll know how to procede from here

P.S:簡化為CSS以消除噪音所需的東西。你會知道怎么從這里開始


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/03/29/729b30441abe7721dd724806df6f5293.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com