简体   繁体   English

较少嵌套选择器

[英]LESS nesting with selectors

I have the following code 我有以下代码

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

        :placeholder-shown{
        opacity: 1;
    }
    }

It results in the following CSS 结果为以下CSS

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

And that fires and error of a bad selector. 这会触发错误的选择器并引发错误。 how to make less treat it correctly like 如何减少对它的正确对待

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

You forgot to use & 您忘记了使用&

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

Will result to 将导致

.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 资料来源: lesscss.org

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM