h1在.title选择器中的Sass嵌套

h1在.title选择器中的Sass嵌套,sass,Sass,我试过无礼的话 .title { font-weight: bold; // more title styles &h1 { font-size: 30px; } } 产生的css是: .titleh1 { font-weight: bold; // more title styles } .titleh1 { font-size: 30px; } 我是否可以将h1嵌套在.title中以提供这样的css输出 .t

我试过无礼的话

.title {
    font-weight: bold;
    // more title styles
    &h1 {
        font-size: 30px;
    }
}
产生的css是:

.titleh1 {
    font-weight: bold;
    // more title styles
}
.titleh1 {
    font-size: 30px;
}
我是否可以将h1嵌套在.title中以提供这样的css输出

.titleh1 {
    font-weight: bold;
    // more title styles
}
h1.title {
    font-size: 30px;
}
是的,您只需要跳出嵌套选择器:

.title {
    font-weight: bold;
    // more title styles

    @at-root {
      h1#{&} {
        font-size: 30px;
      }
    }
  }
是的,您只需要跳出嵌套选择器:

.title {
    font-weight: bold;
    // more title styles

    @at-root {
      h1#{&} {
        font-size: 30px;
      }
    }
  }

你好,谢谢Seth,它编译到了
h1.title{font-size:30px;}
,我正在寻找编译到
h1.title{font-size:30px;}
(h1和.title之间没有空格)@Davey将
h1&
更改为
h1.{&
。嗨,谢谢Seth,它编译到了
h1.title{font-size:30px;}
,我正在寻找编译成
h1.title{font size:30px;}
(h1和.title之间没有空格)@Davey将
h1&
更改为
h1{&