[英]Is there a way to adjust the angle of the linear gradient in Tailwind CSS?
有没有办法使用 Tailwind CSS 调整 HTML 组件的背景图像样式的线性渐变角度?
我唯一能做的就是在方向选项之间进行选择: t(top)
、 tr(top-right)
等,但我想将带有 Tailwind class 之类的 hr 元素的渐变角度设置为 24 度,例如.bg-gradient-[160deg]
(和 colors: .from .from-lime
.to .to-red
)
当然,您可以为此任务编写一个简单的插件
const plugin = require('tailwindcss/plugin')
module.exports = {
theme: {
extend: {
// custom user configuration
bgGradientDeg: {
75: '75deg',
}
}
},
plugins: [
plugin(function({ matchUtilities, theme }) {
matchUtilities(
{
'bg-gradient': (angle) => ({
'background-image': `linear-gradient(${angle}, var(--tw-gradient-stops))`,
}),
},
{
// values from config and defaults you wish to use most
values: Object.assign(
theme('bgGradientDeg', {}), // name of config key. Must be unique
{
10: '10deg', // bg-gradient-10
15: '15deg',
20: '20deg',
25: '25deg',
30: '30deg',
45: '45deg',
60: '60deg',
90: '90deg',
120: '120deg',
135: '135deg',
}
)
}
)
})
],
}
并像使用它一样
<div class="h-40 from-red-500 via-yellow-500 to-blue-500 bg-gradient-90">
90 deg from defaults
</div>
<div class="h-40 from-red-500 via-yellow-500 to-blue-500 bg-gradient-10 sm:bg-gradient-60">
10 deg on mobile,
60 on desktops
</div>
<div class="h-40 from-red-500 via-yellow-500 to-blue-500 bg-gradient-[137deg] sm:bg-gradient-to-br">
137 deg from JIT on mobile,
to bottom right on desktop
</div>
<div class="h-40 from-red-500 via-yellow-500 to-blue-500 bg-gradient-75">
75 deg from user's custom config
</div>
如果有帮助,我刚刚为 Tailwind v3 创建了简单的package
.repeating-linear {
background: repeating-linear-gradient(-45deg, red, red 5px, blue 5px, blue 10px);
}
通过在 class 中给出具有重复线性梯度的角度来尝试此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.