简体   繁体   English

忽略没有值的样式声明是 SCSS

[英]Ignore style declaration without value is SCSS

In my scss file I am importing a third-party css file在我的 scss 文件中,我正在导入第三方 css 文件

  @import 'icons/third-party-icons/style';

Unfortunately, this style is missing the value for the color style不幸的是,这种风格缺少颜色风格的价值

.mySelector {
  content: "\eac2";
  margin-left: -1em;
  color: ;
}

As expected, node-sass is throwing the following error:正如预期的那样,node-sass 抛出以下错误:

ModuleBuildError: Module build failed (from./node_modules/sass-loader/lib/loader.js): ModuleBuildError:模块构建失败(来自./node_modules/sass-loader/lib/loader.js):

color: ;颜色: ; ^ Style declaration must contain a value ^ 样式声明必须包含一个值

Is there any way to configure node-sass to ignore this invalid property?有没有办法配置 node-sass 来忽略这个无效的属性?

In my opinion, that error report is there for a reason, you shouldn't have empty definitions as that is technically an error.在我看来,那个错误报告是有原因的,你不应该有空的定义,因为这在技术上是一个错误。 In unminified CSS you wouldn't have an issue it would just appear as strikethrough in the element inspector in the browser, but in this case you break the minify process.在未缩小的 CSS 中,您不会遇到问题,它只会在浏览器的元素检查器中显示为删除线,但在这种情况下,您会破坏缩小过程。

Instead of importing it you can download the CSS code if possible and save it in your project locally then solve the issues manually.如果可能,您可以下载 CSS 代码,而不是导入它,并将其保存在本地项目中,然后手动解决问题。 It won't matter what you do later in your CSS file, the error will appear.无论您稍后在 CSS 文件中做什么,都会出现错误。 Or else you can try to link the CSS in the header.或者你可以尝试在header中链接CSS。 If you are using PHP or similar serverside scripting then create a separate header.php (for example) and include it into every file.如果您使用 PHP 或类似的服务器端脚本,则创建一个单独的 header.php(例如)并将其包含到每个文件中。 This way you will need to copy and paste the link once and you can access the style at every page.这样,您将需要复制并粘贴一次链接,并且您可以在每个页面上访问该样式。

You could override the imported css.您可以覆盖导入的 css。 The code is looking to use a value, but can't because it's null.该代码正在寻找使用一个值,但不能因为它是 null。

You could include in your style tags:您可以在样式标签中包含:

.mySelector {
    color: black !important;
}

That,important will override whatever is imported from the stylesheet.那,important 将覆盖从样式表中导入的任何内容。 and you class in the body will use that color instead of trying to use the null color.并且您在正文中的 class 将使用该颜色,而不是尝试使用 null 颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM