简体   繁体   English

CSS菜单未居中

[英]CSS menu isn't centered

I have built this menu: 我建立了这个菜单:
JSBIN EDIT ; JSBIN编辑 ; JSBIN DEMO JSBIN演示
As you see, the menu isn't centered at the middle of the bar, he's centered up. 如您所见,菜单不在居中位置,而是居中。 However, I want to make it go lower, exactly at the middle. 但是,我想降低它,恰好在中间。

So, I had an idea to do margin-top: 26px because the bar's height is 53 pixels, but it doesn't change anything. 因此,我有一个想法可以做margin-top: 26px因为条形的高度为53像素,但它没有任何改变。 I also did margin: 0 auto and text-align:center . 我也做了margin: 0 autotext-align:center

I read this STACKOVERFLOW and realized that it is related in float, but I don't want to float it - I want to make it go down. 我阅读了此STACKOVERFLOW,并意识到它与float相关,但我不想使其浮动-我想使其下降。

Thank you! 谢谢!

You need to give the line height by using line-height . 您需要使用 line-height来指定 line-height Okay, updated , the line-height trick doesn't work!!! 好的, 已更新line-height不起作用!!! And also, giving this to the <a> tag does the trick: 而且,将其赋予<a>标记也可以达到目的:

width: auto;
display: inline-block;

Fiddle: http://jsbin.com/cayob/2 小提琴: http : //jsbin.com/cayob/2

尝试将链接的line-height设置为条形的高度,在此示例中为53像素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM