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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 10:08:50  来源:igfitidea点击:

Remove white space on ul with css

htmlcsshtml-lists

提问by Aeross

I'm trying to remove some white space on the left of a fixed top menu ulbut 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 underscore

DEMO

演示

As you code padding: 0;to the #nav

当你编码padding: 0;#nav

回答by Airen

add padding:0;and margin:0to 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>.