I'm working on a iPad-specific website. To make my website work on both the retina display iPad and older versions of iPads, I want to set a variable in LESS CSS in media query like:
@media all and (max-width: 768px) {
@ratio: 1;
}
@media all and (min-width: 769px) {
@ratio: 2;
}
So when you are setting anything in pixels, you can do
width: 100px * @ratio;
But I got a compile error saying @ratio is not defined. Is it possible to have a workaround to make it work? Thanks.
It would be nice, but this is impossible to do like this.
LESS compiles your media queries to actual media queries, so at compile time there is no indication of which media query will be relevant to the browser.
After compile time you just have CSS not less so you can't have variables anymore.
You can do this instead but it isn't as elegant:
@base_width: 100px;
@media all and (max-width: 768px) {
.something {
width: @base_width;
}
}
@media all and (min-width: 769px) {
.something {
width: @base_width * 2;
}
}