Less.js: 媒体查询:即使没有 --strict-math=on 也需要括号

创建于 2013-08-09  ·  7评论  ·  资料来源: less/less.js

此示例在小于 1.3.3 和 1.4.2 下产生不同的输出:

.foo (@dpr) {
    <strong i="6">@dpi</strong>: <strong i="7">@dpr</strong> * 96dpi;
    <strong i="8">@query</strong>: ~'(min-resolution: @{dpi})';
    <strong i="9">@media</strong> <strong i="10">@query</strong> {
    }
}
.foo(2);

小于 1.3.3 的输出:

<strong i="14">@media</strong> (min-resolution: 192dpi) {

}

小于 1.4.1 的输出:

<strong i="18">@media</strong> (min-resolution: 2 * 96dpi) {

}

<strong i="21">@dpr</strong> * 96dpi周围添加括号可以减少 1.4.1 输出与 1.3.3 相同,但这是升级到 1.4.x 时的一个意外问题。

bug high priority

最有用的评论

:+1: 在 2.5.1 上也看到了这个。 建议在媒体查询中的变量周围加上括号的解决方法有效。

小问题案例:

<strong i="7">@foo</strong>: 10px;
<strong i="8">@bar</strong>: 20px;
<strong i="9">@baz</strong>: <strong i="10">@foo</strong> + @bar;

.test {
  <strong i="11">@media</strong> (min-width: @baz) {
    color: red;
  }
}

琐碎问题案例的编译CSS(无效):

<strong i="15">@media</strong> (min-width: 10px + 20px) {
  .test {
    color: red;
  }
}

带有解决方法的微不足道的问题案例:

<strong i="19">@foo</strong>: 10px;
<strong i="20">@bar</strong>: 20px;
<strong i="21">@baz</strong>: <strong i="22">@foo</strong> + @bar;

.test {
  <strong i="23">@media</strong> (min-width: (@baz)) {
    color: red;
  }
}

带有解决方法的琐碎问题案例的编译CSS:

<strong i="27">@media</strong> (min-width: 30px) {
  .test {
    color: red;
  }
}

所有7条评论

啊,有点边缘情况……我们在媒体查询中强制使用严格的数学,以便人们可以使用分数,感谢您提出问题。

:+1: 在 2.5.1 上也看到了这个。 建议在媒体查询中的变量周围加上括号的解决方法有效。

小问题案例:

<strong i="7">@foo</strong>: 10px;
<strong i="8">@bar</strong>: 20px;
<strong i="9">@baz</strong>: <strong i="10">@foo</strong> + @bar;

.test {
  <strong i="11">@media</strong> (min-width: @baz) {
    color: red;
  }
}

琐碎问题案例的编译CSS(无效):

<strong i="15">@media</strong> (min-width: 10px + 20px) {
  .test {
    color: red;
  }
}

带有解决方法的微不足道的问题案例:

<strong i="19">@foo</strong>: 10px;
<strong i="20">@bar</strong>: 20px;
<strong i="21">@baz</strong>: <strong i="22">@foo</strong> + @bar;

.test {
  <strong i="23">@media</strong> (min-width: (@baz)) {
    color: red;
  }
}

带有解决方法的琐碎问题案例的编译CSS:

<strong i="27">@media</strong> (min-width: 30px) {
  .test {
    color: red;
  }
}

我们在 Moodle 中也受到此问题的影响,因为此问题会影响 bootstrap 的 2.3 版本。

在这种情况下,变量被分配(https://github.com/twbs/bootstrap/blob/v2.3.2/less/variables.less#L181):

<strong i="7">@navbarCollapseWidth</strong>:             979px;
<strong i="8">@navbarCollapseDesktopWidth</strong>:      <strong i="9">@navbarCollapseWidth</strong> + 1;

媒体查询是(https://github.com/twbs/bootstrap/blob/v2.3.2/less/responsive-navbar.less#L181):

<strong i="13">@media</strong> (min-width: @navbarCollapseDesktopWidth) {
}

这导致输出:

<strong i="17">@media</strong> (min-width: 979px + 1) {
}

https://tracker.moodle.org/browse/MDL-53152

我尝试做类似的事情

<strong i="6">@media</strong> (min-width: <strong i="7">@navbarCollapseWidth</strong> + 1) { }

以避免创建额外的 less 变量,但这不起作用,为什么?

以避免创建额外的 less 变量,但这不起作用,为什么?

目前@media语句中的算术表达式需要括号,例如:

<strong i="9">@media</strong> (min-width: (<strong i="10">@navbarCollapseWidth</strong> + 1)) { }

我收到一个错误

<strong i="6">@media</strong> (max-width: (<strong i="7">@sm</strong> -1)) {
  .hidden-sm-down{  // hide anything up to small size
    display: none;
  }
} 

从 http://localhost:63342/foo/app/app.js 上的“app/app”加载“app/styles/index.less!$less”时出错,预期为')'"

我收到一个错误

您将<strong i="7">@sm</strong> -1<strong i="9">@sm</strong> - 1 (第一个不是算术表达式,而是两个值列表)。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

matthew-dean picture matthew-dean  ·  6评论

bassjobsen picture bassjobsen  ·  6评论

briandipalma picture briandipalma  ·  6评论

moshemo picture moshemo  ·  7评论

heavyk picture heavyk  ·  3评论