Html 用css删除ul上的空白
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17129891/
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
Remove white space on ul with css
提问by Aeross
I'm trying to remove some white space on the left of a fixed top menu ul
but I'm stuck, I already searched and put this:
我正在尝试删除固定顶部菜单左侧的一些空白区域,ul
但我被卡住了,我已经搜索并放置了这个:
#nav li {
list-style: none;
display: inline-block;
}
I want to put all the list at the left (like left: 0
?), but something is producing some white space on the left of the first list item.
我想把所有的列表放在左边(比如left: 0
?),但有些东西在第一个列表项的左边产生了一些空白。
Why is this happening, and how can I remove it?
为什么会发生这种情况,我该如何删除它?
Here is the code (fiddle):
这是代码(小提琴):
#contenedormenu {
background-color: #FFFFFF;
width: 100%;
position: fixed;
top: 0px;
box-shadow: 0px 1px 2px #888;
height: 40px;
z-index: 1;
}
#menu {
width: 100%;
height: 40px;
position: fixed;
top: 0px;
}
#nav {
width: 100%;
height: 40px;
top: 0px;
position: fixed;
margin-top: 0px;
}
#nav li {
margin-top: 10px;
list-style: none;
display: inline-block;
}
#nav li a {
color: #5D5D5D;
font-family: Lobster, Arial, sans-serif;
font-size: 16px;
padding: 10px 5px 12px 5px;
text-decoration: none;
text-shadow: rgba(255, 255, 255, 0.6) 1px 1px 0;
}
#nav a:hover {
background-color: #f15a24;
color: white;
text-shadow: none;
}
<div id="contenedormenu">
<div id="menu">
<ul id="nav">
<li id="inicio">
<a href="#home" title="Home">Home</a>
</li>
<li id="item1">
<a href="#home">Menu item 2</a>
</li>
<li id="item2">
<a href="#home">Menu Item 3</a>
</li>
</ul>
</div>
</div>
回答by Airen
add padding:0;
and margin:0
to the <ul>
.
添加padding:0;
和margin:0
到<ul>
.
回答by Huy Nguy?n
With <ul>
tag set:
带<ul>
标签集:
font-size: 0px;
With <li>
tag set:
带<li>
标签集:
font-size: 14px; /*or custom*/
Other solution: https://davidwalsh.name/remove-whitespace-inline-block
其他解决方案:https: //davidwalsh.name/remove-whitespace-inline-block
回答by Niet the Dark Absol
Add padding: 0;
to the <ul>
.
添加padding: 0;
到<ul>
.