0

I'm creating clock with CSS (LESS). I'm adding loop to align digits in circle with LESS loops. But it's showing a parsing error.

.clock-digits{
    position: absolute;
    bottom: 50%;
    left: 50%;
    width: 2px;
    height: @clock-digits/2;
    transform-origin: bottom center;
    &:after{
        content: attr(data-digit);
        position: absolute;
        top: 5px;
        left: 50%;
        display: block;
        border-radius: 50%;
        border: 1px solid red;
        width: 30px;
        height: 30px;
        margin-left:(-30px/2);
        font-size: 2em;
        line-height: 30px;
        text-align: center;
    }
    .mixin-loop (@i) when (@i > 0){
        &:nth-child(@{i}){
            transform: rotate((@{i} * 360 / @clock-digits)deg);
            &:after{
                transform: rotate(-(@{i} * 360 / @clock-digits)deg);
            }
        }
        .mixin-loop(@i - 1);
    }

    .mixin-loop(@clock-digits);
}
1
  • What is the parsing error? Commented Nov 5, 2021 at 15:55

1 Answer 1

2

The problem is with @{i} in the mathematical operation within the mixin. @{var} format is needed only when doing interpolation (variable/selector/property). For this case, just @i would suffice.

.mixin-loop (@i) when (@i > 0){
    &:nth-child(@{i}){
        transform: rotate(unit((@i * 360 / @clock-digits),deg));
        &:after{
            transform: rotate(unit(-(@i * 360 / @clock-digits),deg));
        }
    }
    .mixin-loop(@i - 1);
}

Additional Note: Also, it is better to use the built-in unit() function with deg as the second parameter to convert a number to degrees than using string concatenation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.