css - 如何防止 compass 处理并替换我的变量的 unicode 值?

标签 css unicode gruntjs compass grunt-contrib-compass

这是我声明每个图标的 unicode 的示例。

$icomoon-font-path: "fonts" !default;

$mr-employee-board-1: "\e90a";
$mr-employee-board-2: "\e90b";
$mr-employee-calendar: "\e90c";
$mr-employee-compare-vertical: "\e90d";
$mr-employee-compare: "\e90e";
$mr-employee-financial: "\e90f";
$mr-employee-stats: "\e910";
$mr-employee: "\e911";
$mr-file-history: "\e912";
$mr-health-board: "\e913";

这是 css 输出。

/* line 14, ../vendor-styles/mr-material/style.scss */
.mr {
  /* use !important to prevent issues with browser extensions that change fonts */
  font-family: 'mr-material' !important;
  speak: none;
  font-style: normal;
  font-weight: normal;
  font-variant: normal;
  text-transform: none;
  line-height: 1;
  /* Better Font Rendering =========== */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* line 30, ../vendor-styles/mr-material/style.scss */
.mr-employee-board-1:before {
  content: "";
}

/* line 35, ../vendor-styles/mr-material/style.scss */
.mr-employee-board-2:before {
  content: "";
}

/* line 40, ../vendor-styles/mr-material/style.scss */
.mr-employee-calendar:before {
  content: "";
}

/* line 45, ../vendor-styles/mr-material/style.scss */
.mr-employee-compare-vertical:before {
  content: "";
}

/* line 50, ../vendor-styles/mr-material/style.scss */
.mr-employee-compare:before {
  content: "";
}

这是我的 IDE 中的样子

This is how it looks like in my IDE

我的图标是这样显示的

UI after the compilation

是否有可能阻止这种行为?

我正在运行 grunt-contrib-compass@1.0.4

compass: {
      options: {
        sassDir: '<%= yeoman.app %>/scss',
        cssDir: '<%= yeoman.app %>/styles/',
        generatedImagesDir: '.tmp/images/generated',
        imagesDir: '<%= yeoman.app %>/images',
        javascriptsDir: '<%= yeoman.app %>/scripts',
        fontsDir: '<%= yeoman.app %>/fonts',
        importPath: './bower_components',
        httpImagesPath: '/images',
        httpGeneratedImagesPath: '/images/generated',
        httpFontsPath: '/styles/fonts',
        relativeAssets: false,
        assetCacheBuster: false,
        raw: 'Sass::Script::Number.precision = 10\n'
      },
      dist: {
        options: {
          generatedImagesDir: '<%= yeoman.dist %>/images/generated'
        }
      },
      server: {
        options: {
          sourcemap: true
        }
      }
    },

最佳答案

我通过查看图标字体的其他 sass 实现找到了问题的答案。所以,我们要做的第一件事就是像这样编写一个转义函数:

@function char($character-code) {
  @if function-exists("selector-append") {
    @return unquote("\"\\#{$character-code}\"");
  }

  @if "\\#{'x'}" == "\\x" {
    @return str-slice("\x", 1, 1) + $character-code;
  }
  @else {
    @return #{"\"\\"}#{$character-code + "\""};
  }
}

然后我们所要做的就是像这样定义我们的变量:

$mr-employee-board-1: char(e90a);
$mr-employee-board-2: char(e90b);
$mr-employee-calendar: char(e90c);

这将防止 compass 改变我们变量的内容。 就这样。

关于css - 如何防止 compass 处理并替换我的变量的 unicode 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41452612/

相关文章:

html - 无法将 Div 居中放置在页面中间

c++ - boost 属性 ptree : boost write_xml adding unicode 0x0 character in child element in xml file

python - 抓取外文网页标题后在终端获取解码结果

javascript - 在 "module"全局变量上运行 grunt-typescript 时,angular-mock 和 node.js 发生冲突

javascript - 使用 requirejs 和 grunt 构建多客户端项目

html - 元素符号列表和 HTML 表格

html - br 没有按要求工作

javascript - 在 Twitter Bootstrap 轮播中显示下一张和上一张图像

Python - 使用 unicode 抓取网站

javascript - string.replace 不在 grunt 和 grunt-angular-templates 中链接