阅读(4714) (0)

Tailwind CSS 线条

2022-07-25 17:35:12 更新

线条

用于设置 SVG 元素线条(stroke)样式的功能类。

Class
Properties
stroke-current stroke: currentColor;

使用

使用 stroke-current 将 SVG 的 stroke 颜色设置为当前的文本颜色。通过将该类与现有的文本颜色功能类相结合,可以轻松设置元素的 stroke 颜色。

对于像 Heroicons 这样完全用 stroke 绘制的图标集很有用。


<svg class="stroke-current text-purple-600 ..."></svg>

自定义

通过在您的 ​tailwind.config.js​ 文件中自定义 ​theme.stroke​ 部分来控制 Tailwind 生成哪些 ​stroke ​功能类。

  // tailwind.config.js
  module.exports = {
    theme: {
     stroke: {
       current: 'currentColor',
     }
     stroke: theme => ({
       'red': theme('colors.red.500'),
       'green': theme('colors.green.500'),
       'blue': theme('colors.blue.500'),
     })
    }
  }

变体

默认情况下, 针对 stroke 功能类,只生成 responsive 变体。

您可以通过修改您的 ​tailwind.config.js​ 文件中的 ​variants ​部分中的 ​stroke ​属性来控制为 stroke 功能生成哪些变体。

例如,这个配置也将生成 hover and focus 变体:

  // tailwind.config.js
  module.exports = {
    variants: {
      extend: {
        // ...
       stroke: ['hover', 'focus'],
      }
    }
  }

禁用

如果您不打算在您的项目中使用 stroke 功能,您可以通过在配置文件的 ​corePlugins ​部分将 ​stroke ​属性设置为 ​false ​来完全禁用它们:

  // tailwind.config.js
  module.exports = {
    corePlugins: {
      // ...
     stroke: false,
    }
  }