【问题标题】:Is there a way to use a certain font for <p> on Tailwind Typography有没有办法在 Tailwind Typography 上为 <p> 使用某种字体
【发布时间】:2021-11-02 16:06:24
【问题描述】:

例如,假设我要使用以下降价

# AAAAAAAAAa

BBBBBBB

将被相应地解析为 AAAAAAAAAa 是 h1 并且 BBBBBB&lt;p&gt;,并且所有这些都包含在使用 Tailwind Typographyprose div 中。在正常情况下,两者将共享tailwind.config.js 中定义的相同字体,我想知道如何更改此设置以使两者具有不同的字体。

【问题讨论】:

    标签: css reactjs next.js tailwind-css


    【解决方案1】:

    您提供的链接上有示例。看看CustomizationModifiers

    您可以直接将属性添加到某些元素(h1,h2,h3,p 等)。请参见下面的示例:

    // tailwind.config.js
    
    module.exports = {
      theme: {
        extend: {
          typography: {
            DEFAULT: {
              css: {
                color: '#333',
                h1: {
                  fontFamily: ['Roboto', 'sans-serif'],
                },
                p: {
                  fontFamily: ['Montserrat', 'sans-serif'],
                },
              },
            },
          }
        },
      },
      plugins: [
        require('@tailwindcss/typography'),
        // ...
      ],
    }
    

    或者您可以像这样创建自己的修饰符:

    // tailwind.config.js
    
    module.exports = {
      theme: {
        extend: {
          typography: {
            '3xl': {
              css: {
                fontSize: '1.875rem',
                h1: {
                  fontSize: '4rem',
                  fontFamily: ['Montserrat', 'sans-serif'],
                },
                p: {
                  fontSize: '1.5rem',
                  fontFamily: ['Roboto', 'sans-serif'],
                },
                // ...
              },
            },
          },
        }
      },
      plugins: [
        require('@tailwindcss/typography'),
        // ...
      ],
    }
    

    A simple demo.

    【讨论】:

      猜你喜欢
      • 2021-12-27
      • 2022-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-06
      • 2018-07-17
      • 2018-05-15
      相关资源
      最近更新 更多