如果您想在每个 li 中将每个单独的锚标记居中:
如果您可以将锚标签的高度设置为固定数字,那么the following 可以工作:
#nav a.rhlink:link, #nav a.rhlink:active, #nav a.rhlink:visited {
display: block;
padding: 0px 5px;
text-decoration: none;
color: inherit;
position: absolute;
top: 50%;
font-size: 12px;
margin-top: -12px;
text-align: center;
width: 90%;
}
如果你不知道列表项的高度,你可能不得不使用像this这样的javascript:
$('a').each(function() {
$(this).css("top", Math.max(0, (($(this).parent().height() - $(this).outerHeight()) / 2)) + "px");
});
如果你想在窗口中将整个列表项集居中:
如果 ul 标签的高度保持一致,你可以做类似this:
#nav {
position: absolute;
top: 50%;
margin-top: -5em;
}
如果您希望导航包裹并仍然显示在精确的中心,您可能不得不使用像this这样的小javascript:
$('#nav').css("top", Math.max(0, (($(window).height() - $('#nav').outerHeight()) / 2) + $(window).scrollTop()) + "px");