Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS [Solved] Adventures with SASS ampersand

  • This topic is empty.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #189421
    elneco
    Participant

    Dear Forums,

    Im trying to do this:
    http://codepen.io/jq/pen/gbpNvx

    any ideas?
    -Jaime

    #189424
    Paulie_D
    Member

    This..

    
    p.a { color: green; }
    

    …is not a parent selector. It’s a p with a class of ‘a’.

    The ampersand selects the parent selector not the parent style.

    http://thesassway.com/intermediate/referencing-parent-selectors-using-ampersand

    #189434
    elneco
    Participant

    I understand. In this case I want to combine my parent selector .a with the p tag nested in that block.

    Does anyone know of a way to do this?

    #189435
    Paulie_D
    Member

    In this case I want to combine my parent selector .a with the p tag nested in that block.

    Yes but that’s

    
    .a p { color: green; }
    

    not

    
    p.a { color: green; }
    
    #189437
    Paulie_D
    Member

    This SCSS

    
    p {
      color: red;
       .a & {
        color: green;
      }
     }
    

    compiles to

    
    p {
      color: red;
    }
    .a p {
      color: green;
    }
    
    #189442
    elneco
    Participant

    heres another way to think about what Im trying to accomplish:

    In the style block for .a {} – I want to check if this class is attached to a particular tag. If that tag is a p tag I want to alter the styles for that scenario.

    I would like to know if this can be accomplished in that same style block?

    #189443
    Paulie_D
    Member

    In the style block for .a {} – I want to check if this class is attached to a particular tag. If that tag is a p tag I want to alter the styles for that scenario.

    CSS can’t ‘check’ anything…it can only style based on a selector.

    http://codepen.io/Paulie-D/pen/yyNmrJ

    Basically, I don’t think you can define what you are after within the ‘a’ style block….it just doesn’t work that way….AFAIK.

    #189444
    __
    Participant

    there’s no reason to complicate this.

    .a
        color: red
    p.a
        color: green
    
    #189448
    elneco
    Participant

    ok looks like this really isn’t possible in sass at the moment:
    ‘& must appear at the beginning of a compound selector’
    http://sass-lang.com/documentation/file.SASS_REFERENCE.html

    #244124
    elneco
    Participant

    SO this is now possible in Sass – here is the solution:
    .class-name {
    @at-root {
    a#{&} {
    color: fourteen;
    }
    }
    }

    props: https://twitter.com/antimytheme/status/757712441753108481

Viewing 10 posts - 1 through 10 (of 10 total)
  • The forum ‘CSS’ is closed to new topics and replies.