0

您好,我无法在无序列表中获得垂直居中的锚标记。我的 CSS 是:

*{ margin: 0; padding: 0;}

html {
    height: 100%;
    font-size: 16px;
}

body {
    font-family: 'Montserrat', sans-serif;
    font-size: 62.5%;
    background-color:rgba(0,0,0, 0.7);
    height: 100%;
}

.container {
    margin-left: 9.814814814814815%; /* 106 / 1080 */
    margin-right: 10.092592592592593%; /* 109 / 1080 */
    width: 80%; /* 864 / 1080 */
    height: 100%;
}

nav ul{
    list-style-type: none;
}

nav ul li {
    display: inline-block;
}

nav ul li a {
    color: white;
    text-transform: uppercase;
    text-decoration: none;
    font-size: 2em;
}

nav {
    background-color: black;
    margin-top: 5.0595238095238096%; /* 85 / 1680 */
    height:  5.476190476190476%; /* 92 / 1680 */
}

然后这是我的html:

<div class="container">
    <nav>
        <ul>
            <li><a href="/">home</a></li>
            <li><a href="/get_involved">get involved</a></li>
        </ul>
    </nav>
</div>
4

1 回答 1

0

<a>要实现“垂直居中”,请在元素中添加 line-height 或 padding :

nav ul li a {
    color: white;
    text-transform: uppercase;
    text-decoration: none;
    font-size: 2em;
    padding: 10px 0;
}

您还可以调整父元素的高度<li>以微调“居中”。

于 2012-06-02T01:54:23.617 回答