Created
June 15, 2021 15:33
-
-
Save jayantbh/98a97ec219f212dc58b63eb3db136647 to your computer and use it in GitHub Desktop.
Tailwind Empty Pseudo-Selector Variant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`; | |
}); | |
}); | |
}), | |
], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example:
To hide (
display: none
) an element if it's empty, use this class:empty:hidden
.