Html 无法使用 CSS 增加水平菜单项之间的间距
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23506141/
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
Having trouble increasing spacing between horizontal menu items with CSS
提问by codacopia
Here is the HTML:
这是 HTML:
<div id="menu">
<ul>
<li><a href="#">Home</a>
</li>
<li><a href="#">Blog</a>
</li>
<li><a href="#">About</a>
</li>
<li><a href="#">Contact</a>
</li>
</ul>
</div>
Here is the CSS:
这是CSS:
li {
display:inline;
padding: 10px;
}
#menu {
margin: 21px 646px 21px 646px;
}
I cannot seem to increase the space between the menu items. What should I adjust to do so?
我似乎无法增加菜单项之间的空间。我应该如何调整才能这样做?
回答by CRABOLO
try
尝试
a {
display: block;
padding: 10px 30px;
}
edit
编辑
Do you want something like this ? http://jsfiddle.net/Y8Ng7/
你想要这样的东西吗?http://jsfiddle.net/Y8Ng7/
Just remove that ridiculous margin you have for the nav and increase the li padding
只需删除导航的可笑边距并增加 li 填充
li {
display:inline;
padding: 10px 40px;
}
To center a div element, don't do margin: 21px 646px 21px 646px;
要居中一个 div 元素,不要做 margin: 21px 646px 21px 646px;
just do margin: 21px auto;
做就是了 margin: 21px auto;
回答by Ajay Gupta
回答by Benjamin
Rather than trying to manipulate the list items, try adding your padding to the anchor. Ex:
与其尝试操作列表项,不如尝试将填充添加到锚点。前任:
#menu li a { padding: 10px; display: block; }