Answer the question
In order to leave comments, you need to log in
LESS. Is it possible to convert px to rem without mixins?
Hello.
Interested in the possibility of automatic conversion to other units of measurement using parameterized variables.
For example, a variable of type is created @value()
, and when you write a value in parentheses px
, it gives the result in rem
to the property in which it is specified.
Something like:
.block {
width: @value(100);
}
.block {
width: 6.25rem;
}
Answer the question
In order to leave comments, you need to log in
There is no way with standard tools, in less it seems like there are no user functions, but you can add an extension to JS, on stackoverflow somewhere there was a similar question and this answer:
em: function(less, fontsize, basefontsize){
if (less.functions.functionRegistry.get('ispixel')){
basefontsize = (basefontsize) ? basefontsize.value : 16
return fontsize.value/basefontsize+'em';
}
}
.block {
font-size: em(16px);
}
There really are no user-defined functions, but, as an option, you can take this thing:
And multiply by it in those places where you need to convert px to rem:
p {
font-size: @rem * 50;
border: @rem * 5 solid #000;
padding: @rem * 10;
/* В CSS получится
font-size: 3.125rem;
border: 0.3125rem solid #000;
padding: 0.625rem;
*/
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question