Generate styles using LESS recursive function and media queries

吃可爱长大的小学妹 提交于 2019-12-02 05:03:35

问题


I am trying to generate some relative to screen height and decided to try to use LESS to generate something like that, even if a bit heavy just as a test:

@baseHeight: 1px;
.setRelativeHeight(@screenHeight, @minHeightDiff, @maxHeightDiff) when(@screenHeight < 2400) {

    @media (min-height: @baseHeight * @screenHeight) {
        min-height: @baseHeight * (@screenHeight - @minHeightDiff);
        max-height: @baseHeight * (@screenHeight - @maxHeightDiff);
    }
    .setRelativeHeight(@screenHeight + 20, @minHeightDiff, @maxHeightDiff);
}

That seems to work, most of it, but this is part of what it generates when calling it:

@media not all {
#ConversationMessages .messages {
    max-height: 2100px;
    min-height: 2000px;
}
}
@media not all {
#ConversationMessages .messages {
    max-height: 2120px;
    min-height: 2020px;
}
}
@media not all {
#ConversationMessages .messages {
    max-height: 2140px;
    min-height: 2040px;
}
}
@media not all {
#ConversationMessages .messages {
    max-height: 2160px;
    min-height: 2060px;
}
}

So the styles are being set properly but the media condition is lost :( Does anyone know why? :)

Thanks!!

Update Fixed adding parenthesis to the media condition (see comment below).


回答1:


Arithmetic operations inside @media queries should always be in parens regardless of --strict-math option. I.e. should be @media (min-height: (@baseHeight * @screenHeight)).



来源:https://stackoverflow.com/questions/24241544/generate-styles-using-less-recursive-function-and-media-queries

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!