html - 在无序列表中定位 <div> 时的垂直对齐

标签 html css markup

我已将搜索框添加为 <ul> 中的列表项元素如下:

<nav id="notifications-menu">
    <ul id="display-inline-block">
        <li><a class="normal calendar" onclick="showUserCalendar('/', false);" href="#">My Calendar</a></li>
        <li><a class="normal calendarteam" onclick="showTeamCalendar('/', false);" href="#">Team Calendar</a></li>

        <li><div id="global-search-wrapper">
            <input type="text" class="global-search-box" name="s" value="type search term..." />
            <input type="image" src="/images/general/blank.gif" class="global-search-submit" value="" />
        </div></li>
    </ul>
</nav>

应用以下 CSS 时,我得到以下输出。我想让列表项文本居中对齐(垂直):

enter image description here

nav#notifications-menu  { 
    font-family: 'Adelle', sans-serif;
    float:right;
    height: 52px; 
    width:600px;
    min-width:300px;
    padding: 0px 18px 0px 0px;
    text-align:right;
    font-size:13px;
}


nav#notifications-menu #display-inline-block,
nav#notifications-menu #display-inline-block li {
    /* Setting a common base */
    margin: 0;
    padding: 0;

}

nav#notifications-menu #display-inline-block li {
    display: inline-block;
}

nav#notifications-menu #display-inline-block li a.normal {
    color: #f0f0f0;
    text-decoration:none;
    margin-right:18px;
    padding-left:24px;

    background-repeat:no-repeat;


}
nav#notifications-menu #display-inline-block li a.envelope {
        background-image:url(../images/general/envelope.png);
            background-position: 0px 1px;
}
nav#notifications-menu #display-inline-block li a.calendar {
        background-image:url(../images/general/calendar.png);
            background-position: 0px -2px;
}
nav#notifications-menu #display-inline-block li a.calendarteam {
        background-image:url(../images/general/calendar_team.png);
            background-position: 0px -2px;
}

#global-search-wrapper {
    width: 234px;
    height: 30px;
    background-image: url(../images/general/search-box.png);
    background-repeat: no-repeat;
    padding: 0px;
    margin: 12px 0px 0px 0px;
    position: relative; }

    #searchwrapper form {
        display: inline;
        border: 0px; }

.global-search-box {
    border: 0px;
    background-color: transparent;
    position: absolute;
    top: 1px;
    left: 9px;
    width: 206px;
    height: 28px;
    color: #999999;
    font-style: italic;
    border:0px !important; }

.global-search-submit {
    border: 0px;
    background-color: transparent;
    position: absolute;
    top: 1px;
    left: 200px;
    width: 32px;
    height: 28px; }

任何帮助将不胜感激!

最佳答案

只需向 li 元素添加一个 vertical-align 即可,例如

nav#notifications-menu #display-inline-block li {
    display: inline-block;
    vertical-align: middle;
}

因为基线是默认对齐方式

关于html - 在无序列表中定位 <div> 时的垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10191447/

相关文章:

javascript - 如何更改转换 : translate() position of an element as one scrolls through a website?

html - div 在 Chrome 中消失了

html - 向非程序员解释什么是 <div> 标签

mediawiki - 如何将包含双大括号函数的 Wikitext 标记转换为纯文本或 html?

html - CSS 表格单元格输入不占全宽

javascript - 在 Weebly 中维护产品图像大小和纵横比

javascript - 在段落标题中添加单引号和空格

javascript - 单击关闭选项卡

css - IE8 CSS Body 背景色

ios - CSS :hover iOS - on/off