【问题标题】:Can you import a css file and use sass to iterate each of the rules and append !important?你可以导入一个 css 文件并使用 sass 来迭代每个规则并附加 !important 吗?
【发布时间】:2019-05-20 01:38:42
【问题描述】:

你能拿一个文件并用 sass 稍微更新每个 css 规则吗?例如

style.scss

  .bold {
    font-weight: 600
  }
  .bolder {
    font-weight: 800
  }
// ...

style-important.scss

// Here I want to import and produce the following:

  .bold-important {
    font-weight: 600 !important;
  }
  .bolder-important {
    font-weight: 800 !important;
  }

sass 可以制作这个吗?另一个 css 预处理器能做到这一点吗?

【问题讨论】:

  • 如果您必须在所有规则之后加上!important,您应该重新考虑 CSS 的设计。
  • @HereticMonkey 或者重新考虑工作,我相信设计好的 CSS 是贵公司的首要任务。

标签: css sass stylesheet meta


【解决方案1】:

抱歉,Sass 无法做到这一点。您可以做的最好的事情是在这样的数组中循环:

@each $animal in puma, sea-slug, egret, salamander {
    .#{$animal}-icon {
      background-image: url('/images/#{$animal}.png');
    }
}

但这并不能解决你的问题

【讨论】:

  • 添加到 sass 有多难?这将是一个非常有用的功能。
  • 我不知道实现它会有多难,但是是的,这将是一个有趣的功能。之后应该知道 sass 更倾向于快速生成 css 而不是解析它。
  • 感谢您的尝试,虽然它没有回答最初的问题,所以我不能给你任何东西。
猜你喜欢
  • 2012-08-07
  • 1970-01-01
  • 1970-01-01
  • 2010-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-22
相关资源
最近更新 更多