Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "$root: &" mean in sass?

Tags:

variables

sass

I'm trying to understand sass files of Splide ( https://splidejs.com/ ).

In many files there are codes like this one

.splide {
    $root: &;

    &--ttb {
        > #{$root}__pagination {
            display:        flex;
            right:          1em;
            bottom:         50%;
            left:           auto;
            flex-direction: column;
            transform:      translate(0, 50%);

            #{$root}__pagination__page {
                width:  $indicator-height;
                height: $indicator-width;
            }
        }
    }
}

What the $root: &; means?

like image 211
Glob Dug Avatar asked Jan 31 '26 19:01

Glob Dug


1 Answers

In your snippet, $root is just the name of the variable.
You could give it another name, like $foo.

$root: & is equivalent here to $root: .splide as & in sass refers to the parent selector.

It means that:

.splide {
    $root: &;

    &--ttb {
        > #{$root}__pagination {
            display:        flex;
            right:          1em;
            bottom:         50%;
            left:           auto;
            flex-direction: column;
            transform:      translate(0, 50%);

            #{$root}__pagination__page {
                width:  $indicator-height;
                height: $indicator-width;
            }
        }
    }
}

Is equivalent to:

.splide {
    &--ttb {
        > .splide__pagination {
            display:        flex;
            right:          1em;
            bottom:         50%;
            left:           auto;
            flex-direction: column;
            transform:      translate(0, 50%);

            .splide__pagination__page {
                width:  $indicator-height;
                height: $indicator-width;
            }
        }
    }
}

And will compile to:

.splide--ttb > .splide__pagination {}
.splide--ttb > .splide__pagination .splide__pagination__page {}
like image 78
Amaury Hanser Avatar answered Feb 03 '26 07:02

Amaury Hanser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!