Skip to content

Instantly share code, notes, and snippets.

@jayantbh
Created June 15, 2021 15:33
Show Gist options
  • Save jayantbh/98a97ec219f212dc58b63eb3db136647 to your computer and use it in GitHub Desktop.
Save jayantbh/98a97ec219f212dc58b63eb3db136647 to your computer and use it in GitHub Desktop.
Tailwind Empty Pseudo-Selector Variant
const plugin = require("tailwindcss/plugin");
// tested for tailwindcss 2.1.2
module.exports = {
// other config
variants: {
extend: {
// other variant extensions
display: ["empty"],
},
},
plugins: [
// other plugins
plugin(function ({ addVariant, e }) {
addVariant("empty", ({ modifySelectors, separator }) => {
modifySelectors(({ className }) => {
return `.${e(`empty${separator}${className}`)}:empty`;
});
});
}),
],
};
@jayantbh
Copy link
Author

Example:
To hide (display: none) an element if it's empty, use this class: empty:hidden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment