Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How to remove a particular selector.

Required SASS

.a {
    .b {
        .c {
            .d {
                .g {
                    ...
                }
            }
        }

        .c > {
            .e {
                .h {
                    ...
                }
            }
            .f {
                ...
            }
        }
    }
}

Generated

.a .b .c .d .g { ... }
.a .b .c > .e .h { ... }
.a .b .c > .f { ... }

Combined SASS

.a {
    .b {
        .c > {
            .d { // remove > for .d
                .g {
                    ...
                }
            }
            .e {
                .h {
                    ...
                }
            }
            .f {
                ...
            }
        }
    }
}

Generated

.a .b .c > .d .g { ... } // extra  > 
.a .b .c > .e .h { ... }
.a .b .c > .f { ... }

How to remove > selector for .d and it's siblings in the above SASS, so that it is efficient, rather than re-writing the same selector multiple times?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
206 views
Welcome To Ask or Share your Answers For Others

1 Answer

If I understood you correctly, you can achieve this using @at-root:

.a {
    .b {
        .c > {
            @at-root .a .b .c {
                .d {
                    .g {
                        color: red;
                    }
                }
            }
            .e {
                .h {
                    color: red;
                }
            }
            .f {
                color: red;
            }
        }
    }
}

Which will generate:

.a .b .c .d .g {
  color: red;
}
.a .b .c > .e .h {
  color: red;
}
.a .b .c > .f {
  color: red;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...