Add ancestor selector in current SASS nesting

后端 未结 1 1330
天涯浪人
天涯浪人 2021-01-15 02:15

I would like to use Modernizr classes but I can\'t see how to do it properly with SASS in a current nesting selectors.

How to optimize:

.page-home
           


        
相关标签:
1条回答
  • 2021-01-15 02:59
    .page-home
        .content
            .rows
                .row
                    background: blue
    
                    html.no-touch &:hover
                        background: red
    
            .images
                width: auto
    
                html.touch &
                    max-width: 50px
    

    Will render:

    .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; }          
    

    See SASS referencing parent selectors and this post for another example.

    0 讨论(0)
提交回复
热议问题