gpt4 book ai didi

html - 如何在不使用显示 : table-cell? 的情况下使文本垂直居中

转载 作者:太空宇宙 更新时间:2023-11-03 22:02:57 25 4
gpt4 key购买 nike

我试图让菜单出现在 30px 行的中间,但问题是我无法将它从顶部移动,除非我使用 display: table-cell。

这里有什么问题吗?

样式表文件:

div.menu
{
width: 600;
height: 30px;
border: 1px solid black;
margin: 0px auto;
text-align: center;
vertical-align: bottom
}

我的 html 文件中的菜单代码:

<div class="space"></div>
<div class="menu">
<a href="index.html">Home</a>
<a href="index.html">Home</a>
<a href="index.html">Home</a>
<a href="index.html">Home</a>
<a href="index.html">Home</a>
</div>
<div class="space"></div>

最佳答案

line-height: 100px; 设置菜单行的高度。但是在水平维度上要保持足够的空间,否则你会看到疯狂的景色。期待 min-widthwidthoverflow-x 规则。

div.menu
{
width: 600px;
/* Use line-height instead of height */
line-height: 30px;
border: 1px solid black;
margin: 0px auto;
text-align: center;
}

div.menu a {
vertical-align: middle;
}

关于html - 如何在不使用显示 : table-cell? 的情况下使文本垂直居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9140780/

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