gpt4 book ai didi

html -
  • 菜单中的链接垂直居中
  • 转载 作者:搜寻专家 更新时间:2023-10-31 22:29:47 25 4
    gpt4 key购买 nike

    我有这个菜单:

    <div id="menu">

    <ul>
    <li><a href="./index.html" target="_parent" class="current">Home</a></li>
    <li><a href="./programm.html" target="_parent">Programm & Preise</a></li>
    <li><a href="./kuenstler.html">Künstler</a></li>
    <li><a href="./rueckblick.html">Rückblick</a></li>
    <li><a href="./team.html" target="_parent">Team</a></li>
    </ul>

    </div> <!-- end of menu -->

    这是我目前拥有的 css:

    /* menu */
    #menu {
    clear: both;
    width: 670px;
    height: 64px;
    background: url(images/menu_yellow.png) no-repeat bottom;
    }

    #menu ul {
    margin: 0;
    padding: 0;
    list-style: none;
    }

    #menu ul li {
    padding: 0;
    margin: 0;
    display: inline;
    }

    #menu ul li a{
    float: left;
    display: block;
    width: 94px;
    height: 55px;
    padding: 7px 0 0 0;
    margin-right: 5px;
    text-align: center;
    font-size: 13px;
    text-decoration: none;
    color: #000;
    font-weight: normal;
    outline: none;
    background: url(http://i.imgur.com/JYsyCl6.png) repeat;
    opacity: .7;
    }

    #menu li a:hover, #menu li .current{
    color: #C30;
    background: url(http://i.imgur.com/JYsyCl6.png) repeat;
    opacity: 1;
    }

    链接水平居中,但是否也可以在 <li> 中垂直居中?包含它们?

    我读到了 vertical-align: middle ;但仅将其添加到链接中是行不通的。

    这是一个 fiddle :http://jsfiddle.net/gkpfL/

    最佳答案

    你正在使用 float: left; 所以你不需要 display: block;

    所以首先,你不需要 display: block; 当你 float 时,甚至 inline 元素变成 float block ,到目前为止随着垂直居中的进行,不使用 float,而是使用 display: table-cell;vertical-align: middle;

    Demo

    #menu ul li a{
    display: table-cell; /* Add this */
    vertical-align: middle; /* Add this */
    width: 94px;
    height: 55px;
    padding-bottom: 5px;
    /* Use this for a spare bottom space for your background-image */

    /* Rest of the properties goes here */
    }

    还对 li 元素使用 display: inline-block; 而不是 display: inline;vertical-align: top; (不是必需的,但安全总比后悔好)

    #menu ul li {
    padding: 0;
    margin: 0;
    display: inline-block;
    vertical-align: top;
    }

    关于html - <li> 菜单中的链接垂直居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21433552/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com