使用 jquery 插入 LI 元素看起来与硬编码的不同

发布于 2024-12-17 03:02:08 字数 186 浏览 3 评论 0原文

我有一个菜单(参见示例)。它有两行。上面的一个是硬编码的,下面的一个是用jquery插入的。问题是,上面一行的 LI 元素之间有一些间距,而下面一行则没有。我缺少什么?

示例: http://jsfiddle.net/s3rVg/

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

未央 2024-12-24 03:02:08

如果删除上面列表元素 [li] 之间的空格,html 也会丢失它的空格。喜欢:

<li class="" onclick="/admin/oink;">Oink</li><li class="" onclick="/admin/super;">Piglet</li>

由于这使 html 变得丑陋,您可能还想看看这个讨论。尤其是乔恩·格兰特的答案可能是一个选择。

If you delete the whitespace between the upper list elements [li] the html looses it whitespace as well. Like:

<li class="" onclick="/admin/oink;">Oink</li><li class="" onclick="/admin/super;">Piglet</li>

As this uglifies the html you may also wanna take a look at this discussion. Especially Jon Grant's answer might be an option.

腻橙味 2024-12-24 03:02:08

答案非常简单:

您在两个硬编码的

  • 项中插入了一个加号空格。
  • 看看这里::)

    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/

    ˉ厌 2024-12-24 03:02:08

    在 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 write margin: 0; it will remove the spaces of the li. 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.

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文