在Tailwind CSS排版插件中覆盖前伪元素的内容。

huangapple go评论55阅读模式
英文:

Overwrite content of before pseudo-element in tailwind css typography plugin

问题

我想自定义 Tailwind 的 prose 类(typography 插件的默认行为)。具体来说,我想移除 code::beforecode::after 中的反引号。

我尝试了以下方法:

tailwind.config.js

/** @type {import('tailwindcss').Config} */

import defaultTheme from 'tailwindcss/defaultTheme';

module.exports = {
  content: [],
  theme: {
    extend: {
      typography: {
        DEFAULT: {
          css: {
            code: {
              'background-color': '#e5e7eb',
              // before 和 after 仍然显示反引号,但应为空
              '&::before': {
                content: '""',
              },
              '&::after': {
                content: '""',
              },
              'border-radius': '0.25rem',
            }
          }
        }
      }
    }
  },
  plugins: [
    require('@tailwindcss/typography'),
  ],
}

这是在 Firefox Dev Tools 中的结果:

在Tailwind CSS排版插件中覆盖前伪元素的内容。

我该如何修复这个问题?提前感谢。

有关链接:

英文:

I want to customize default behavior of tailwind's prose class from typography plugin. Specifically I want to remove backticks from code::before and code::after.

I've tried the following approach:

tailwind.config.js

/** @type {import('tailwindcss').Config} */

import defaultTheme from 'tailwindcss/defaultTheme'

module.exports = {
  content: [],
  theme: {
    extend: {
      typography: {
        DEFAULT: {
          css: {
            code: {
              'background-color': '#e5e7eb',
              // before and after are still showing backticks, but should be empty
              '&::before': {
                content: '""',
              },
              '&::after': {
                content: '""',
              },
              'border-radius': '0.25rem',
            }
          }
        }
      }
    }
  },
  plugins: [
    require('@tailwindcss/typography'),
  ],
}

Here is the result in Firefox Dev Tools:

在Tailwind CSS排版插件中覆盖前伪元素的内容。

How can I fix this? Thanks in advance.

Relevant links:

答案1

得分: 0

module.exports = {
  theme: {
    extend: {
      typography: {
        DEFAULT: {
          css: {
            'code::before': {
              content: 'normal',
            },
            'code::after': {
              content: 'normal',
            },
            code: {
              'background-color': '#e5e7eb',
              'border-radius': '0.25rem',
            },
          },
        },
      },
    },
  },
  plugins: [require('@tailwindcss/typography')],
}
英文:

The before and after pseudo elements need to be defined like this:

/** @type {import('tailwindcss').Config} */
module.exports = {
  theme: {
    extend: {
      typography: {
        DEFAULT: {
          css: {
            'code::before': {
              content: 'normal',
            },
            'code::after': {
              content: 'normal',
            },
            code: {
              'background-color': '#e5e7eb',
              'border-radius': '0.25rem',
            },
          },
        },
      },
    },
  },
  plugins: [require('@tailwindcss/typography')],
}

https://play.tailwindcss.com/1dD9LnWSHW?file=config

huangapple
  • 本文由 发表于 2023年7月13日 18:08:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76678220.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定