如何在 HTML 中设置列表项的高度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3080673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set height of list items in HTML?
提问by nectar
Here is my code:
这是我的代码:
HTML
HTML
<div class="menu">
<ul>
<li class="active"><a href="index.html">HOME</a></li>
<li class="active"><a href="#">COMPANY</a></li>
<li class="active"><a href="#">SOLUTIONS</a></li>
<li class="active"><a href="#">SERVICES</a></li>
<li class="active"><a href="#">NEWS & EVENTS</a></li>
<li class="active"><a href="#">BLOGS</a></li>
<li class="active"><a href="#">CONTACTS</a></li>
</ul>
</div>
CSS
CSS
.header .menu ul { margin:33px 10px 0 0; padding:0; float:right; width:auto; height:12px; list-style:none;}
.header .menu ul li { margin:0 4px; float:left;}
It does not recognize the heightfeature. Why? How can I set the height of menu item?
它无法识别高度特征。为什么?如何设置菜单项的高度?
采纳答案by scum
You're missing a semicolon :-)
你少了一个分号:-)
You can also try setting the line-height property of the li tags to change the position of the text in the element.
你也可以尝试设置 li 标签的 line-height 属性来改变文本在元素中的位置。
回答by Babiker
.header .menu ul { margin:33px 10px 0 0; padding:0; float:right; width:auto;list-style:none;}
.header .menu ul li { margin:0 4px; float:left;}
.active{height:50px;}
回答by Patrick Hendricks
ul is set to a height of 12 pixels, at least in Firefox.
ul 设置为 12 像素的高度,至少在 Firefox 中是这样。
回答by Ryan Kinal
Is the height set on the correct element? You're asking how to set the height of a menu item (presumably, an li
) but your CSS says you're setting the height of the ul
. Perhaps, moving height: 12px;
from where it is to .header .menu ul li
could help.
高度是否设置在正确的元素上?您正在询问如何设置菜单项(大概是li
)的高度,但您的 CSS 说您正在设置ul
. 也许,height: 12px;
从它所在的地方移动到.header .menu ul li
可能会有所帮助。