Tailwind CSS 字體粗細

2022-08-08 10:02 更新

字體粗細

用來控制字體粗細的功能類

Class
Properties
font-thin font-weight: 100;
font-extralight font-weight: 200;
font-light font-weight: 300;
font-normal font-weight: 400;
font-medium font-weight: 500;
font-semibold font-weight: 600;
font-bold font-weight: 700;
font-extrabold font-weight: 800;
font-black font-weight: 900;

使用方法

使用 ?font-{weight}? 功能類來控制元素字體粗細。


<p class="font-thin ...">The quick brown fox ...</p>
<p class="font-extralight ...">The quick brown fox ...</p>
<p class="font-light ...">The quick brown fox ...</p>
<p class="font-normal ...">The quick brown fox ...</p>
<p class="font-medium ...">The quick brown fox ...</p>
<p class="font-semibold ...">The quick brown fox ...</p>
<p class="font-bold ...">The quick brown fox ...</p>
<p class="font-extrabold ...">The quick brown fox ...</p>
<p class="font-black ...">The quick brown fox ...</p>

響應式

要在特定的斷點處控制元素的字體粗細,請在任何現(xiàn)有的字體粗細功能類前添加 ?{screen}:? 前綴。例如,使用 ?md:font-bold? 來僅在中等大小及以上的屏幕應用 ?font-bold? 功能類。

<p class="font-normal md:font-bold ...">The quick brown fox jumps over the lazy dog.</p>

關于 Tailwind 的響應式設計功能的更多信息,請查看 響應式設計 文檔。

自定義

Font Weights

默認情況下,Tailwind 提供 10 個 ?font-weight? 實用程序。您可以通過編輯 Tailwind 配置的 ?theme.fontWeight? 部分來更改、添加或刪除這些內容。

  // tailwind.config.js
  module.exports = {
    theme: {
      fontWeight: {
       hairline: 100,
       'extra-light': 100,
       thin: 200,
        light: 300,
        normal: 400,
        medium: 500,
       semibold: 600,
        bold: 700,
       extrabold: 800,
       'extra-bold': 800,
        black: 900,
      }
    }
  }

變體

默認情況下, 針對 font weight 功能類,只生成 responsive 變體。

您可以通過修改您的 ?tailwind.config.js? 文件中的 ?variants ?部分中的 ?fontWeight ?屬性來控制為 font weight 功能生成哪些變體。

例如,這個配置也將生成 hover and focus 變體:

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

禁用

如果您不打算在您的項目中使用 font weight 功能,您可以通過在配置文件的 ?corePlugins ?部分將 ?fontWeight ?屬性設置為 ?false ?來完全禁用它們:

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


以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號