gpt4 book ai didi

CSS垂直居中内联元素?

转载 作者:行者123 更新时间:2023-11-28 13:55:33 25 4
gpt4 key购买 nike

您好,我无法在无序列表中获得垂直居中的 anchor 标记。我的 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>

最佳答案

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

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

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

关于CSS垂直居中内联元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10859057/

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