2013-06-27 62 views
0

这是那些日子之一,我不知道为什么我在下面的代码中获得每个LI标签左侧的空间。如果你把鼠标悬停在菜单上,你会看到我的意思。导航UL/LI额外空间

http://jsfiddle.net/midnitesonnet/C2Dub/

<div id="wrapper"> 
    <div id="menu"> 
     <ul> 
      <li><a href="#!1">Home</a></li> 
      <li><a href="#!2">Home</a></li> 
      <li><a href="#!3">Home</a></li> 
     </ul> 
    </div> 
    <div id="content">Content</div> 
    <div id="footer">Footer</div> 
</div> 
+0

的http:// css-tricks.com/fighting-the-space-between-inline-block-elements/ – fcalderan

+0

可能更容易,只是漂浮他们! –

回答

0

我想不通为什么我得到一个空间,每一个LI的左侧标签

因为你display:inline-block格式化 - 标签之间有空格。这是基本的“HTML行为”,两个内嵌(-block)元素之间的任何空格在显示时会压缩为一个空格字符。

无论float the LI instead,或write them without whitespace between the tags,这意味着...</li><li>...

-1

ü有你的HTML代码之间的一些空白字符尽量把李标签上eachtoher:

<ul> 
    <li><a href="#!1">Home</a></li> 
    <li><a href="#!2">Home</a></li> 
    <li><a href="#!3">Home</a></li> 
</ul> 

这在小提琴解决了这个问题。

0

试试这个

http://jsfiddle.net/C2Dub/4/

/* CSS Document */ 

body { 
    font-family: Arial, Helvetica, sans-serif; 
    font-size: 0.9em; 
    margin-top: 0px; 
    background-color: #f5f5f5; 
} 

#wrapper { 
    background-color: #ffffff; 
    width: 1000px; 
    margin: auto; 
    -webkit-box-shadow: 0px 0px 6px rgba(50, 50, 50, 0.64); 
    -moz-box-shadow: 0px 0px 6px rgba(50, 50, 50, 0.64); 
    box-shadow:   0px 0px 6px rgba(50, 50, 50, 0.64); 
    /*-webkit-border-radius: 15px; 
    -moz-border-radius: 15px; 
    border-radius: 15px;*/ 
} 

#menu { 
    background: #505050; 
    background: -moz-linear-gradient(top, #505050 0%, #343434 50%); 
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#505050), color-stop(50%,#343434)); 
    background: -webkit-linear-gradient(top, #505050 0%,#343434 50%); 
    background: -o-linear-gradient(top, #505050 0%,#343434 50%); 
    background: -ms-linear-gradient(top, #505050 0%,#343434 50%); 
    background: linear-gradient(to bottom, #505050 0%,#343434 50%); 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#505050', endColorstr='#343434',GradientType=0); 
    min-height: 26px; 

    color: #CCC; 
} 
#menu ul { 
    display: block; 
    height: 39px; 
    list-style: none outside none; 
    margin: 0; 
    padding: 0; 
} 
#menu li { 
    margin: 0; 
    display: inline-block; 
    height: 39px; 
    border-right: 1px solid rgb(0, 0, 0); 
    padding: 0px 20px !important; 
    line-height: 39px; 
    list-style: none; 
    float:left; 
} 

#menu li a { 
    display: inline-block; 
    width: 99%; 
    color: #CCC; 
    text-decoration: none; 
} 
#menu li:hover { 
    background: #6b6b6b; 
    background: -moz-linear-gradient(top, #6b6b6b 0%, #4c4c4c 100%); 
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6b6b6b), color-stop(100%,#4c4c4c)); 
    background: -webkit-linear-gradient(top, #6b6b6b 0%,#4c4c4c 100%); 
    background: -o-linear-gradient(top, #6b6b6b 0%,#4c4c4c 100%); 
    background: -ms-linear-gradient(top, #6b6b6b 0%,#4c4c4c 100%); 
    background: linear-gradient(to bottom, #6b6b6b 0%,#4c4c4c 100%); 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#6b6b6b', endColorstr='#4c4c4c',GradientType=0); 

} 

#content { 
    min-height: 600px; 
    padding: 5px; 
} 

#footer { 
    min-height: 50px; 
    background: #f4f7f5; 
    background: -moz-linear-gradient(top, #f4f7f5 0%, #edf5f7 37%, #d3e8e6 100%); 
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f4f7f5), color-stop(37%,#edf5f7), color-stop(100%,#d3e8e6)); 
    background: -webkit-linear-gradient(top, #f4f7f5 0%,#edf5f7 37%,#d3e8e6 100%); 
    background: -o-linear-gradient(top, #f4f7f5 0%,#edf5f7 37%,#d3e8e6 100%); 
    background: -ms-linear-gradient(top, #f4f7f5 0%,#edf5f7 37%,#d3e8e6 100%); 
    background: linear-gradient(to bottom, #f4f7f5 0%,#edf5f7 37%,#d3e8e6 100%); 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f4f7f5', endColorstr='#d3e8e6',GradientType=0); 
    border-top: 1px #D2D2D2 solid; 
} 
0

这似乎是工作,我飘来贵丽的,去掉一些填充,改变了菜单的高度:http://jsfiddle.net/C2Dub/5/

#menu { 
    background: #505050; 
    background: -moz-linear-gradient(top, #505050 0%, #343434 50%); 
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#505050), color-stop(50%,#343434)); 
    background: -webkit-linear-gradient(top, #505050 0%,#343434 50%); 
    background: -o-linear-gradient(top, #505050 0%,#343434 50%); 
    background: -ms-linear-gradient(top, #505050 0%,#343434 50%); 
    background: linear-gradient(to bottom, #505050 0%,#343434 50%); 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#505050', endColorstr='#343434',GradientType=0); 
    min-height: 39px; 

    color: #CCC; 
} 
#menu ul { 
    display: block; 
    padding: 0; 
    margin: 0; 
    list-style: none; 
} 
#menu li { 
    margin: 0; 
    float: left; 
    height: 19px; 
    border-right: 1px solid rgb(0, 0, 0); 
    padding: 10px 20px !important; 
    list-style: none; 
}