Calculate using mathematical operations in LESS

1

I'm trying to add a number with a string and LESS is not interpreting as I wanted, see example:

@screen-sm: 768;
@screen-md: 1024;

.col-tablet(@rules) {
  @media (min-width: @screen-sm+'px') and (max-width: @screen-md+-1+'px') {
        @rules();
    }
}

.col-tablet({
  display: block;
});

and the output:

@media (min-width: 768 'px') and (max-width: 1024+-1 'px') {
  display: block;
}
    
asked by anonymous 06.08.2017 / 03:42

1 answer

1

The problem is that in Less you do not need to add number with string

Do the following, change your variables to:

@screen-sm: 768px;
@screen-md: 1024px;

I think you're doing a subtraction when you run:

@screen-md+-1

So, change to:

.col-tablet(@rules) {
  @media (min-width: @screen-sm) and (max-width: (@screen-md - 1)) {
        @rules();
    }
}

For more information and examples of how to use it, access the less link

    
06.08.2017 / 06:02