我可以关闭SASS RGB - >颜色名称 [英] Can I turn off SASS RGB -> Color Name

查看:142
本文介绍了我可以关闭SASS RGB - >颜色名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的CSS规则:

I have a CSS rule like this:

background: #fff url('/assets/img/file.png');

正在编译至:

background: white url("/assets/img/file.png");

有什么办法防止它转换吗?在我的页面上有JS寻找RGB值,我不想在一些hacky函数中将这些字符串转换为RGB。

Is there any way to prevent it from converting it like that? There is JS on my page that looks for RGB values and I don't want to have to convert those strings to RGB in some hacky function.

推荐答案

默认情况下,除非你强制Sass用#{} 或一个变量插值,否则Sass不会从十六进制值转换文字颜色值。

By default, Sass will not convert literal color values from their hex values unless you are forcing Sass to interpolate with #{} or a variable.

使用插值将返回您感兴趣的值的to_sass版本。例如,#{#fff} 将内插到白色。这也在变量替换期间发生:当用作变量时,颜色文字被转换为Color对象,然后to_sass被转换到您的样式表中。

Using interpolation will return the "to_sass" version of the value you're interested in. For example, #{ #fff } will interpolate to "white". This also happens during variable replacements: color literals are translated to Color objects when used as variables, then "to_sass"ed into your stylesheet.

选项 compressed ,这将返回较少的字节长度版本(即 red ,而不是 f00 )。由于 white 长度为5个字符,而 #fff 只有4个,所以您的规则将替换为 #fff

Furthermore, you may specify the style option compressed, which will return the less byte-length version (i.e. red instead of #f00). Since white is 5 characters long and #fff is only 4, your rule will replace with #fff instead.

使用变量时,无法关闭反向HTML4颜色名称转换。作为一种解决方法,您可以将颜色变量声明为字符串,然后在样式中使用 unquote()函数。

There is no way to turn off the reverse HTML4 color name conversion when using variables. As a work-around, you can declare color variables as a string, then use then in styles with the unquote() function.

$color: '#fff';
.white { color: unquote($color) }

这篇关于我可以关闭SASS RGB - >颜色名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆