sass / dart-sass

The reference implementation of Sass, written in Dart.
https://sass-lang.com/dart-sass
MIT License
3.97k stars 360 forks source link

An alternate way to define inheritance by utilizing nesting #2189

Closed siMobin closed 8 months ago

siMobin commented 8 months ago

I'd like to propose a different way to define inheritance by nesting the classes within the super class that would allow multiple classes to inherit a class at once without having to inherit them separately.

For example:

.a {
    background-color: red;
    color: white;
    padding: 1em;
}

@extend .a {
    .b {
        margin: 1em;
    }

    .c {
        padding: 5em;
    }

    .d {
        background-color: blue;
    }
}
ntkme commented 8 months ago

If I understand you correctly, you can write:

.a {
    background-color: red;
    color: white;
    padding: 1em;
}

.b, .c, .d {
  @extend .a;
}

.b {
    margin: 1em;
}

.c {
    padding: 5em;
}

.d {
    background-color: blue;
}
nex3 commented 8 months ago

This is a lot of extra, complex syntax for something that (as @ntkme points out) isn't that difficult to do already.

siMobin commented 8 months ago

I believe that sass is made to make css easy to write. So, writing the same thing again and again is annoying, I think. Although sass already supports nesting natively, why doesn't it support the extend method in a similar manner?