如何设置 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
.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;}
它无法识别高度功能。为什么?如何设置菜单项的高度?
Here is my code:
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
.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 height feature. Why? How can I set the height of menu item?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您缺少分号:-)
您还可以尝试设置 li 标记的 line-height 属性来更改元素中文本的位置:
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:
只需根据需要增加 padding-top 和 padding-bottom 即可。线高影响其他。我通过测试发现了这一点。它对我有用。
Just increase the padding-top and padding-bottom as you want. Line height effect other. I found out it by testing it. It work for me.
ul 的高度设置为 12 像素,至少在 Firefox 中是这样。
ul is set to a height of 12 pixels, at least in Firefox.
元素的高度设置正确吗?您询问如何设置菜单项的高度(大概是
li
),但 CSS 表示您正在设置ul
的高度。也许,将height: 12px;
从原来的位置移动到.header .menu ul li
可能会有所帮助。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 theul
. Perhaps, movingheight: 12px;
from where it is to.header .menu ul li
could help.列表的高度不一定会改变可见列表项的高度。我创建了一个小示例来展示这些高度的样子,如果您将鼠标悬停在项目上,您会看到高度在变化。那是因为列表的溢出属性。
无论如何,在您的示例中,HTML 中没有带有类“标题”的 div,这会让初学者感到困惑。您的 CSS 规则以“.header”开头。
The height of the list does not necessarily change the height of the visible list items. I created a small example to show how those heights look like, if you hover on the items, you'll see the height's changing. That because of the overflow attribute of the list.
Anyway, in your example, there's no div with a class "header" in your HTML, that's confusing for beginners. Your CSS rules begin with ".header".