admin管理员组文章数量:1287536
I have the following function in SASS and it mostly works:
@function invert-brightness($color, $limit: 0)
$h: hue($color)
$s: saturation($color)
$l: lightness($color)
$limit: max(0, if($limit > 50, 100 - $limit, $limit))
$v: 100 - $l
@if $v < 50 and $v > $limit
$v: $limit
@else if $v >= 50 and $v < (100 - $limit)
$v: (100 - $limit)
@return hsl($h, $s, $v)
$color
is the original color
$limit
is how far away from 0 or 100 the brightness can be; kind of like clamp($v, 0, $limit)
or clamp($v, $limit, 100)
; used to prevent colors from being too close to 50.
I would use it like this:
.list-selector
$bg-color: #fff
background-color: $bg-color
color: invert-brightness($bg-color, 25)
-- OR --
.list-selector
$bg-color: #111
background-color: $bg-color
color: invert-brightness($bg-color, 25)
-- OR --
.list-selector
$bg-color: #411
background-color: $bg-color
color: invert-brightness($bg-color, 25)
When I do this, it works just fine, but then if I use #f0f000
(hsl(60deg 100% 47%)
), it doesn't look right. It still runs as I scripted it, but their is basicly no contrast.
.list-selector
$bg-color: #f0f000
background-color: $bg-color
color: invert-brightness($bg-color, 25)
I've found several other colors that have the same issue.
I would like a script or function that just works where there are no odd side-cases.
本文标签: Using SASS to invert color brightnessStack Overflow
版权声明:本文标题:Using SASS to invert color brightness - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741239194a2363630.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论