css - 更少的选择器嵌套

标签 css less

我有以下代码

.signin-input{
    input{
        width: 100%;
        height: 2.5rem;
        color: black;

        :placeholder-shown{
        opacity: 1;
    }
    }

它产生以下 CSS

.signin-input input :not(:placeholder-shown) {
  opacity: 1;
}

这会触发错误选择器。如何让 less 像

一样正确对待它
.signin-input input:not(:placeholder-shown) {
      opacity: 1;
}

最佳答案

你忘了使用&

.signin-input {
   input {
      width: 100%;
      height: 2.5rem;
      color: black;
      &:placeholder-shown {
          opacity: 1;
      }
   }
}

将导致

.signin-input input:placeholder-shown {
  opacity: 1;
}

The & operator represents the parent selectors of a nested rule and is most commonly used when applying a modifying class or pseudo-class to an existing selector. source: lesscss.org

关于css - 更少的选择器嵌套,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57432748/

相关文章:

php - jQuery:在隐藏的 Div 上实现 UI 自动完成

css - 更改选项卡文本的颜色和物化框架中的下划线

javascript - jQuery 下拉菜单 : not showing one item

css - 响应式菜单(iphone 5)

javascript - 仅将类添加到一个 div

css - LESS contrast() 函数

linux - CSS 正在生成但未保存

css - 通过 node.js 和 MEAN 堆栈编译 LESS?

less - 使用 webpack、less-loader 和 extract-text-webpack-plugin 避免输出重复

css - 使用 LESS 或 SASS 为 CSS 类名添加前缀