如何编写针对未禁用按钮的选择器的较少的选择器?

发布于 2025-01-29 17:41:14 字数 749 浏览 0 评论 0原文

index.html

<div>
  <span>
    <button disabled>
      Button 1
    </button>
    <button>
      Button 2
    </button>
  </span>
</div>

index.less

:not(&[disabled]) button {
    background-color: red;
}

这给出了以下输出。这两个按钮均为红色,但我试图仅针对未禁用的按钮。

有没有办法做到这一点?我专门寻找未禁用的目标按钮。

这是jsfiddle: https://jsfiddle.net/6gqqb19e3/36/36/36/

index.html:

<div>
  <span>
    <button disabled>
      Button 1
    </button>
    <button>
      Button 2
    </button>
  </span>
</div>

index.less:

:not(&[disabled]) button {
    background-color: red;
}

This gives the below output. Both buttons are colored red but I am trying to target only button that is not disabled.
enter image description here

Is there a way to do this? I am specifically looking to target buttons that are not disabled.

Here is the jsfiddle : https://jsfiddle.net/6gqb19e3/36/

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

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

发布评论

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

评论(1

如梦亦如幻 2025-02-05 17:41:14

我是不熟悉的,我的语法是错误的。经过一点点反复试验,我提出了这一点:

  button {
    background-color: grey;

    &:not([disabled]) {
      background-color: green;
    }
  }

它给出了此输出:

这是: https:/ /

I am new to LESS and my syntax was wrong. After bit of trial and error, I came up with this:

  button {
    background-color: grey;

    &:not([disabled]) {
      background-color: green;
    }
  }

and it gives this output:
enter image description here

Here is the jsfiddle with: https://jsfiddle.net/6gqb19e3/81/

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