A
A
Andrej Sharapov2019-05-13 12:03:34
css
Andrej Sharapov, 2019-05-13 12:03:34

How to make an incremented value in SCSS?

Is it possible to use SASS to gradually increase indentation? Those. each next value should be 5px to the left. Unfortunately, nothing smarter than in the example came to mind, but that's not it.
Here is the code:

@mixin last-childs {
    @for $i from 2 through 7 {
        &:nth-last-child(#{$i}) {
           margin-left: calc(40px - #{$i}px);
        }
    }
}

Or do you have to manually write?
It should be like this:
&:nth-last-child(7) {
        margin-left: 10px;
    }
    &:nth-last-child(6) {
        margin-left: 15px;
    }
    &:nth-last-child(5) {
        margin-left: 20px;
    }
    &:nth-last-child(4) {
        margin-left: 25px;
    }
    &:nth-last-child(3) {
        margin-left: 30px;
    }
    &:nth-last-child(2) {
        margin-left: 35px;
    }
    &:last-child {
        margin-left: 40px;
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Flying, 2019-05-13
@Madeas

In fact, your example is almost correct, just modify a little:

@mixin last-childs {
    @for $i from 7 through 1 {
        &:nth-last-child(#{$i}) {
           margin-left: 40px - 5px * ($i - 1);
        }
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question