oliverdavies.uk/content/node.68735c24-e65b-47f6-9c23-e1be5123f6a6.yml

91 lines
4.4 KiB
YAML

uuid:
- value: 68735c24-e65b-47f6-9c23-e1be5123f6a6
langcode:
- value: en
type:
- target_id: daily_email
target_type: node_type
target_uuid: 8bde1f2f-eef9-4f2d-ae9c-96921f8193d7
revision_timestamp:
- value: '2025-05-11T09:00:50+00:00'
revision_uid:
- target_type: user
target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849
revision_log: { }
status:
- value: true
uid:
- target_type: user
target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849
title:
- value: |
Tailwind CSS' extensibility is one of its best features
created:
- value: '2023-01-03T00:00:00+00:00'
changed:
- value: '2025-05-11T09:00:50+00:00'
promote:
- value: false
sticky:
- value: false
default_langcode:
- value: true
revision_translation_affected:
- value: true
path:
- alias: /daily/2023/01/03/tailwind-css-extensibility-is-one-of-its-best-features
langcode: en
body:
- value: |
<p>As well as the library of utility CSS classes that Tailwind provides, the ability to easily add your own has been one of my main advantages of using it.</p>
<p>You can add your own CSS to a stylesheet within a specific layer, customise the theme settings within a <code>tailwind.config.js</code> file, and write your own custom plugins that you can reuse and even release as separate open-source projects.</p>
<p>Here is a complete plugin that I've added to some projects recently:</p>
<pre><code class="js">const plugin = require('tailwindcss/plugin');
plugin(function({ addVariant }) {
addVariant('hocus', ['&amp;:hover', '&amp;:focus'])
});
</code></pre>
<p>By adding these lines of JavaScript, Tailwind will generate a new set of utility classes that apply styles to both hover and focus states for an element - reducing the number of classes that need to be added and making it more maintainable.</p>
<p>Other plugins that I've written recently include creating different variants of buttons, styling elements within an HTML table (similar to the Tailwind typography plugin), and adding multi-theme support to make components themable with different colours.</p>
<p>I've also released some <a href="https://github.com/opdavies?tab=repositories&amp;q=tailwind-plugin">as open-source projects on GitHub</a>.</p>
<p>The interesting thing is that the plugin API is how Tailwind itself generates its own classes, and I like the stability that provides.</p>
<p>However you extend Tailwind, the fact you can tweak and extend it for each project is great and something that you can't always do or do easily with other tools or frameworks.</p>
format: full_html
processed: |
<p>As well as the library of utility CSS classes that Tailwind provides, the ability to easily add your own has been one of my main advantages of using it.</p>
<p>You can add your own CSS to a stylesheet within a specific layer, customise the theme settings within a <code>tailwind.config.js</code> file, and write your own custom plugins that you can reuse and even release as separate open-source projects.</p>
<p>Here is a complete plugin that I've added to some projects recently:</p>
<pre><code class="js">const plugin = require('tailwindcss/plugin');
plugin(function({ addVariant }) {
addVariant('hocus', ['&amp;:hover', '&amp;:focus'])
});
</code></pre>
<p>By adding these lines of JavaScript, Tailwind will generate a new set of utility classes that apply styles to both hover and focus states for an element - reducing the number of classes that need to be added and making it more maintainable.</p>
<p>Other plugins that I've written recently include creating different variants of buttons, styling elements within an HTML table (similar to the Tailwind typography plugin), and adding multi-theme support to make components themable with different colours.</p>
<p>I've also released some <a href="https://github.com/opdavies?tab=repositories&amp;q=tailwind-plugin">as open-source projects on GitHub</a>.</p>
<p>The interesting thing is that the plugin API is how Tailwind itself generates its own classes, and I like the stability that provides.</p>
<p>However you extend Tailwind, the fact you can tweak and extend it for each project is great and something that you can't always do or do easily with other tools or frameworks.</p>
summary: null
field_daily_email_cta: { }