[英]remove padding from navbar UL css
I am working on something and keep getting some padding on my css navabar, its pretty simple but I cant figure out where it grabbing the padding from pushing it about 5 pixels to the right. 我正在做一些事情,并在我的css navabar上不断获得填充,这很简单,但是我无法从向右推动约5像素来弄清楚它在哪里抓住了填充。
Here is a JSFiddle 这是一个JSFiddle
Notice the little gray space in between the hovered over Update Profile? 请注意,将鼠标悬停在更新配置文件之间有一点灰色空间吗?
I cant seem to find the css anywhere that would cause that. 我似乎找不到任何会导致该问题的CSS。 Anyone notice anything in my code?
有人注意到我的代码中有什么吗? CSS:
CSS:
body {
margin: 20px;
font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Geneva, Verdana, sans-serif;
background-color: #555;
}
#nav {
text-align: center;
}
/* Begin Navigation Bar Styling */
#nav ul {
text-align: center;
font-size: 11px;
width: 100%;
margin: 0;
padding: 0;
display: inline-block;
padding: 0;
list-style: none;
background-color: #f2f2f2;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc;
}
#nav li {
display: inline-block;
}
#nav li a {
display: block;
padding: 8px 15px;
text-decoration: none;
font-weight: bold;
color: #069;
border-right: 1px solid #ccc;
}
#nav li a:hover {
color: #c00;
background-color: #fff;
}
/* End navigation bar styling. */
div {
text-align: center;
}
div#page {
background-color: white;
margin: 0 auto;
text-align: left;
width: 755px;
padding: 0px 10px 0 10px;
}
div#header {
border-bottom: 1px solid black;
height: 30px;
line-height: 30px;
}
div#content {
background: none repeat scroll 0 0 none;
border: 0px solid blue;
width: 100%;
line-height: 500px;
min-height: 500px;
_height: 500px
}
div#footer {
border: 0px solid red;
height: 30px;
line-height: 30px;
border-top: 1px solid black;
font-size: 9pt;
}
HTML: HTML:
<div id="page">
<div id="header">
<div style="float: left;">Welcome Admin</div>
<div style="float: right;">LOGOUT</div>
<div id="nav">
<ul id="nav">
<li><a href="#">Home Page</a>
</li>
<li><a href="#">My Account</a>
</li>
<li><a href="#">Update Profile</a>
</li>
<li><a href="#">Change Avatar</a>
</li>
<li><a href="#">Change Password</a>
</li>
<li><a href="#">Support</a>
</li>
</ul>
</div>
</div>
<div id="content">Content</div>
<div id="footer">
<div style="float: right;">copyright 2014</div>
</div>
</div>
Make the following changes in css for #nav li
: 在
#nav li
CSS中进行以下更改:
#nav li {
float: left;
}
Removed display:inline-block;
删除
display:inline-block;
and replaced it with float: left;
并将其替换为
float: left;
property. 属性。
Update according to @Bokdem's comment 根据@Bokdem的评论进行更新
Keep the css as is: 保持CSS不变:
#nav li {
display: inline-block;
}
And write the content in ul
tag in single line, like: 并将内容写在
ul
标签中的单行中,例如:
<li><a href="#">Home Page</a></li><li><a href="#">My Account</a></li><li><a href="#">Update Profile</a></li><li><a href="#">Change Avatar</a></li><li><a href="#">Change Password</a></li><li><a href="#">Support</a></li>
This will eliminate the extra space. 这将消除多余的空间。
Or 要么
#nav li {
display: inline-block;
margin-left: -4px;
}
Or 要么
Write the content in ul
tag as: 将内容写在
ul
标签中为:
<li><a href="#">Home Page</a></li><!--
--><li><a href="#">My Account</a></li><!--
--><li><a href="#">Update Profile</a></li><!--
--><li><a href="#">Change Avatar</a></li><!--
--><li><a href="#">Change Password</a></li><!--
--><li><a href="#">Support</a></li>
If you use inline-block
element it leaves a gap between successive elements. 如果使用
inline-block
元素,则在连续的元素之间会留有空隙。
You can remove this gap by adding a negative margin. 您可以通过添加负边距来消除此差距。 In your case-
就您而言
#nav li {
margin-right: -3px;
}
You can omit the gap by commenting out white-spaces on your HTML. 您可以通过注释掉HTML上的空格来忽略差距。
<ul id="nav">
<li><a href="#">Home Page</a>
</li><!--
--><li><a href="#">My Account</a>
</li><!--
--><li><a href="#">Update Profile</a>
</li><!--
--><li><a href="#">Change Avatar</a>
</li><!--
--><li><a href="#">Change Password</a>
</li><!--
--><li><a href="#">Support</a>
</li>
</ul>
It does look funky but it works :) 它看起来确实很时髦,但是它可以工作:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.