使用 jquery 插入 LI 元素看起来与硬编码的不同
我有一个菜单(参见示例)。它有两行。上面的一个是硬编码的,下面的一个是用jquery插入的。问题是,上面一行的 LI 元素之间有一些间距,而下面一行则没有。我缺少什么?
I've got a menu (see example). It has two rows. The upper one is hard coded, the bottom one is inserted with jquery. The problem is, the upper row has some spacing between the LI elements, while the bottom ones doesn't have one. What am I missing?
Example: http://jsfiddle.net/s3rVg/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果删除上面列表元素 [
li
] 之间的空格,html 也会丢失它的空格。喜欢:由于这使 html 变得丑陋,您可能还想看看这个讨论。尤其是乔恩·格兰特的答案可能是一个选择。
If you delete the whitespace between the upper list elements [
li
] the html looses it whitespace as well. Like:As this uglifies the html you may also wanna take a look at this discussion. Especially Jon Grant's answer might be an option.
答案非常简单:
您在两个硬编码的
项中插入了一个加号空格。
看看这里::)
http://jsfiddle.net/s3rVg/2/
The answer is quite simple:
You inserted a plus space into the two hard coded
<li>
items.Look at it here: :)
http://jsfiddle.net/s3rVg/2/
在 CSS 中,您编写了
xmargin: 0 5px 0 0 ;
,这是无效的,浏览器无法识别。当您只编写margin: 0;
时,它会删除li
的空格。您应该始终验证您的 CSS!此外,您的代码中有两次相同的 ID,但 ID 对于文档必须是唯一的。
In your CSS you have writen
xmargin: 0 5px 0 0 ;
, this is invalid and not recognized by the browser. When you just writemargin: 0;
it will remove the spaces of theli
. You should always validate your CSS!Also you have the same ID twice in your code, but IDs have to be unique to a document.