【问题标题】:Converting Mixin using Guarded Namespace in Less to Sass在 Less 中使用受保护的命名空间将 Mixin 转换为 Sass
【发布时间】:2016-01-24 11:44:57
【问题描述】:

如何将以下用 LESS 编写的 mixin 转换为 SASS?

.box_gradient (@from, @to) when (iscolor(@from)) and (iscolor(@to)) {
  background-image: -webkit-gradient(linear, left top, left bottom, from(@from), to(@to)); /* Saf4+, Chrome */
  background-image: -webkit-linear-gradient(top, @from, @to); /* Chrome 10+, Saf5.1+, iOS 5+ */
  background-image:    -moz-linear-gradient(top, @from, @to); /* FF3.6 */
  background-image:     -ms-linear-gradient(top, @from, @to); /* IE10 */
  background-image:      -o-linear-gradient(top, @from, @to); /* Opera 11.10+ */
  background-image:         linear-gradient(to bottom, @from, @to);
}

【问题讨论】:

  • SO 不是代码转换服务(参见:meta.stackoverflow.com/questions/296119/…)。你尝试过什么吗?
  • 如果问题是关于受保护的命名空间,源代码不会显示它。
  • @cimmanon 我一直在寻找的是验证是否可以转换这样的东西。一个简单的答案,例如“这可以完成”,使用参考 SCSS 的条件句会是一个更好的答案,而不是提出一个问题是否合适。
  • 你在这里付出了零努力,这就是我想要传达给你的观点。你甚至没有想过守卫是什么,或者一个人如何用一种没有守卫的语言来做某事。它纯粹是“为我翻译一些代码”,我们在这里不这样做。

标签: css sass less mixins less-mixins


【解决方案1】:

这是在 SASS 中使用条件完成的:

.box_gradient (@from, @to) {
  @if (iscolor(@from) and iscolor(@to)) {
    background-image: -webkit-gradient(linear, left top, left bottom, from(@from),   to(@to)); /* Saf4+, Chrome */
    background-image: -webkit-linear-gradient(top, @from, @to); /* Chrome 10+,   Saf5.1+, iOS 5+ */
    background-image:    -moz-linear-gradient(top, @from, @to); /* FF3.6 */
    background-image:     -ms-linear-gradient(top, @from, @to); /* IE10 */
    background-image:      -o-linear-gradient(top, @from, @to); /* Opera 11.10+ */
    background-image:         linear-gradient(to bottom, @from, @to);
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-07
    • 1970-01-01
    • 1970-01-01
    • 2017-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-21
    相关资源
    最近更新 更多