2

我想使用 Modernizr 类,但我看不到如何在当前嵌套选择器中正确使用 SASS。

如何优化:

.page-home
    .content
        .rows
            .row
                background: blue

        .images
            width: auto

html.no-touch
    .page-home
        .content
            .rows
                .row
                    &:hover
                        background: red

html.touch
    .page-home
        .content
            .images
                max-width: 50px

渲染类似:

.page-home .content .rows .row {
    background: blue;
}
html.no-touch .page-home .content .rows .row:hover {
    background: blue;
}
.page-home .content .images {
    width: auto;
}
html.touch .page-home .content .images {
    max-width: 50px;
}           
4

1 回答 1

4
.page-home
    .content
        .rows
            .row
                background: blue

                html.no-touch &:hover
                    background: red

        .images
            width: auto

            html.touch &
                max-width: 50px

将渲染:

.page-home .content .rows .row {
  background: blue; }
  html.no-touch .page-home .content .rows .row:hover {
    background: red; }
.page-home .content .images {
  width: auto; }
  html.touch .page-home .content .images {
    max-width: 50px; }          

有关另一个示例,请参阅SASS 引用父选择器这篇文章

于 2013-05-30T09:47:45.293 回答