last-child and last-of-type not working in SASS

前端 未结 3 1476
梦毁少年i
梦毁少年i 2021-01-01 15:16

How would you write this to be SASS compliant?

.fader { display: inline-block; }
.fader img:last-child {
    position: absolute;
    top: 0;         


        
3条回答
  •  悲哀的现实
    2021-01-01 15:47

    Nesting is not a requirement with Sass. Don't feel obligated to do so if there's no need to break up the selectors.

    .try-me img:last-of-type {
        position: absolute;
        top: 0; 
        left: 0;
        display: none;
    }
    

    If you are applying styles to the image and then specific styles to the last-of-type, then this what it would look like when you nest it:

    .try-me img {
        // styles
    
        &:last-of-type {
            position: absolute;
            top: 0; 
            left: 0;
            display: none;
        }
    }
    

提交回复
热议问题