Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sass scss如何重用内部选择器?_Sass - Fatal编程技术网

Sass scss如何重用内部选择器?

Sass scss如何重用内部选择器?,sass,Sass,我有这样的代码: .outer1 { &.same-inner { background-color: white; } } .outer2 { &.same-inner { background-color: white; } } .outer3 { &.same-inner { background-color: white; } } 如何重复使用。相同的内部选择器 .outer1, .outer2, .outer

我有这样的代码:

.outer1 {
  &.same-inner {
    background-color: white;
  }
}

.outer2 {
  &.same-inner {
    background-color: white;
  }
}

.outer3 {
  &.same-inner {
    background-color: white;
  }
}
如何重复使用。相同的内部选择器

.outer1, .outer2, .outer3 {
  &.same-inner {
    background-color: white;
  }
}
翻译成CSS:

.outer1.same-inner, .outer2.same-inner, .outer3.same-inner {
  background-color: white;
}
.same-inner, .outer1, .outer2, .outer3 {
  background-color: white;
}

.outer1 {
  width: 10px;
}

.outer2 {
  width: 20px;
}

.outer3 {
  width: 30px;
}
或者,如果您想赋予每个外部对象有自己的属性,但也要继承相同的内部对象

.same-inner {
    background-color: white;
}

.outer1 {
    width:10px;
    @extend .same-inner  
}

.outer2 {
    width:20px;
    @extend .same-inner  
}

.outer3 {
    width:30px;
    @extend .same-inner  
}
翻译成CSS:

.outer1.same-inner, .outer2.same-inner, .outer3.same-inner {
  background-color: white;
}
.same-inner, .outer1, .outer2, .outer3 {
  background-color: white;
}

.outer1 {
  width: 10px;
}

.outer2 {
  width: 20px;
}

.outer3 {
  width: 30px;
}
或者你想要的是:

.same-inner {
    background-color: white;
    
   &.outer1 {
        width:10px;
        @extend .same-inner
   }

   &.outer2 {
        width:20px;
        @extend .same-inner
   }
   
   &.outer3 {
        width:30px; 
        @extend .same-inner
   }
    
}
它大量生产CSS:

.same-inner, .same-inner.outer1, .same-inner.outer2, .same-inner.outer3 {
  background-color: white;
}

.outer1.same-inner {
  width: 10px;
}

.outer2.same-inner {
  width: 20px;
}

.outer3.same-inner {
  width: 30px;
}

您可以通过@extend重用选择器

按照此操作