如何在 LessCSS 中只嵌套一层?

发布于 2024-12-26 14:10:22 字数 168 浏览 2 评论 0原文

我正在尝试

li > a

使用 LessCSS 嵌套。这可能吗?

我最初以为可能是这样的

li {
    > a {  }
}

,但这没有用。有什么想法吗?

I'm trying to do

li > a

with LessCSS nesting. Is this possible?

I initially thought maybe something like

li {
    > a {  }
}

But this didn't work. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

烧了回忆取暖 2025-01-02 14:10:22

看起来应该可以工作,但是尝试在组合器之前添加一个&

li {
    & > a {  }
}

LESS 网站 没有提到在将选择器与其他组合器嵌套时使用 &,但话又说回来,那里的文档并不是我见过的最好的。

It looks like that should work, but try adding an & just before the combinator:

li {
    & > a {  }
}

The LESS web site doesn't mention the use of & when nesting selectors with other combinators, but then again the documentation there isn't the best I've seen.

溺深海 2025-01-02 14:10:22

LESS CSS 网站没有提到这些事情,这很令人困惑。但实际上所有类型的选择器都可以工作(即使没有 & 符号)。您可以输入任何 CSS 选择器,它们将正确编译:

p {
    > a { }
    + .class { }
    ~ #named { }
}

在为伪类/元素编写规则时需要 & 符号:

a {
    &:hover { }
    &:last-child { }
    &::before { }
}

您确定它不起作用吗?您使用的是最新版本的 LESS 吗?

The LESS CSS website doesn't mention these things which is quite confusing. But all kinds of selectors actually work (even without the & sign). You can type any of the CSS selectors and they will compile properly:

p {
    > a { }
    + .class { }
    ~ #named { }
}

You need the & sign when writing rules for psedudo-classes/elements:

a {
    &:hover { }
    &:last-child { }
    &::before { }
}

Are you sure it's not working? Are you using the latest version of LESS?

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