【问题标题】:Add ancestor selector in current SASS nesting在当前 SASS 嵌套中添加祖先选择器
【发布时间】:2013-05-25 18:50:22
【问题描述】:

我想使用 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;
}           

【问题讨论】:

    标签: css css-selectors sass modernizr


    【解决方案1】:
    .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 referencing parent selectorsthis post

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-29
      • 2015-02-27
      • 2017-12-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多