gpt4 book ai didi

html - 将菜单文本对齐到 li 的底部

转载 作者:搜寻专家 更新时间:2023-10-31 08:30:50 25 4
gpt4 key购买 nike

我试图将一些文本对齐到 li 的底部(用绿色边框标记),但是“vertical-align: bottom”不起作用,“position: absolute; bottom: 0”导致文本堆积在外面李。我做错了什么?

Jsfiddle:http://jsfiddle.net/eternal_noob/dog42xeh/

HTML:

<div class="head">
<div class="logo"> <a href="/" title="Back to homepage">
<img src="http://www.dierenasielamsterdam.nl/files/homepage/Poes-virtueel-asiel.jpg">
</a>

</div>
<div class="nav">
<div class="icon-top"> <span>(999)999-9999 / (999)999-9999</span>

</div>
<div class="menu">
<ul class="topmenu">
<li><a href="a.php">Abyssinian</a>
</li>
<li><a href="b.php">Munchkin</a>
</li>
<li><a href="c.php">Persian</a>
</li>
<li><a href="d.php">Siamese</a>
</li>
<li><a href="e.php">About</a>
</li>
</ul>
</div>
</div>

CSS:

.head {
text-align: center;
height: 150px
}
.head:before {
content:'';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -0.25em
}
.logo {
display: inline-block;
vertical-align: middle;
height: 100px;
width: 350px;
}
.nav {
display: inline-block;
vertical-align: middle;
height: 100px;
width: 600px;
}
.icon-top {
line-height:29px;
padding-right:20px;
color:#333;
font-size:15px;
text-align:right;
}
.menu {
position: relative;
text-align:right;
}
.menu-header {
height:50px;
}
.topmenu {
display: inline-block;
height:65px;
margin:0;
padding:0;
font-size: 20px;
}
.topmenu li {
display: inline-block;
height:100%;
list-style:none;
margin-left:20px;
border: solid 1px green;
}
.topmenu li a {
color: #000000;
vertical-align:text-bottom;
}
.topmenu li a:hover {
color:#b574d4;
}

最佳答案

你可以像这样添加line-height:

.topmenu li a { 
color: #000000;
line-height: 110px;/*Add this*/
}

fiddle

另一种解决方案是使用table-cell:

.menu {
position: relative;
display: table;/*Add display table*/
margin: 0 auto;/*Add margin 0 auto to align to the middle of the page*/
}

.topmenu {
display: table-row;/*Add display table-row*/
height:65px;
margin:0;
padding:0;
font-size: 20px;
}


.topmenu li {
display: table-cell;/*Add display table-cell*/
/*height:100%; Remove height*/
list-style:none;
margin-left:20px;
border: solid 1px green;
vertical-align: bottom;/*Add vertical-align bottom*/
}

fiddle

看这里:Understanding vertical-align, or "How (Not) To Vertically Center Content"

关于html - 将菜单文本对齐到 li 的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25555040/

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