gpt4 book ai didi

css - 创建 box-shadow to drop-shadow mixin

转载 作者:行者123 更新时间:2023-11-28 15:45:53 27 4
gpt4 key购买 nike

我正在尝试编写一个 mixin,它应该将 CSS box-shadow 作为参数并将其转换为 filter: drop-shadow()

// mixin
drop-shadow($shadows)
$array = split(',', $shadows)
$dropShadows = ()

for $shadow in $array
push($dropShadows, 'drop-shadow(' + $shadow + ')')

filter: unquote(join(' ', $dropShadows))

// usage
body
drop-shadow: 0 0 1px, 0 0 1px

问题是我必须将 drop-shadow 的值作为字符串传递才能使其工作,如果我将它作为数组传递,它不会...

// works
drop-shadow: '0 0 1px, 0 0 1px'

// doesn't work
drop-shadow: 0 0 1px, 0 0 1px

最佳答案

好的,找到解决方案:

// custom property (mixin) which allows you to define a box-shadow that will be
// rendered as `filter: drop-shadow()`
//
// usage:
// drop-shadow: 2px 0 1px rgba(0,0,0,0.5)
// => filter: drop-shadow(2px 0 1px rgba(0,0,0,0.5))

drop-shadow()
$array = arguments
$dropShadows = ()

for $shadow in $array
push($dropShadows, 'drop-shadow(' + $shadow + ')')

filter: unquote(join(' ', $dropShadows))

这将接受 rgb(a) 或 hsl(a) 颜色并像 box-shadow 一样工作

关于css - 创建 box-shadow to drop-shadow mixin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37115729/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com