I am trying to use disabled variant in tailiwnd, but it does not seem to work. I do not know what to do.
I want to change button apperance if it is disabled, I have read the documentation and it says 'disabled' variant in not enabled by default. So I modify my tailwind.config.js and now it looks like this:
module.exports = {
purge: [],
theme: {
extend: {},
},
variants: {
extend: {
opacity: ['disabled']
}
},
plugins: [],
}
I have this code in my page, both buttons look the same:
<div class="text-center space-x-8">
<button type="button" class="py-2 px-4 bg-green-500 text-white font-semibold rounded-lg shadow-md hover:bg-green-700 focus:outline-none disabled:opacity-50" tabindex="-1">
Submit
</button>
<button type="button" class="py-2 px-4 bg-green-500 text-white font-semibold rounded-lg shadow-md disabled:opacity-50" disabled tabindex="-1">
Submit
</button>
</div>
I already re-compiled my code and deleted all my browsers caché, but it still does not work. Do I have to do anything else for this to work?
The disabled attribute is a boolean attribute. When present, it specifies that the button should be disabled. A disabled button is unusable and un-clickable. The disabled attribute can be set to keep a user from clicking on the button until some other condition has been met (like selecting a checkbox, etc.).
Just use last:${yourClassName} to target the last child in your case. Even though the other answer, this answer now points to the best way to do first/last child selection.
The variants section of your tailwind.config.js file is where you control which variants should be enabled for each core plugin: // tailwind.config.js module. exports = { variants: { extend: { backgroundColor: ['active'], // ...
Configuring which utility variants are enabled in your project. The variants section of your tailwind.config.js file is where you control which variants should be enabled for each core plugin:
Here's the link: Upgrade Guide -Tailwind CSS It will change other things that you might want to be aware of. Show activity on this post. It's now possible to enable all variants by default with the new just in time (JIT) compiler. No need to update your Tailwind config file every time you want to add a new variant.
No need to update your Tailwind config file every time you want to add a new variant. 1. Upgrade to TailwindCSS 2.1 or later 2. Enable JIT mode in your config
Every utility class in Tailwind can be applied conditionallyby adding modifier to the beginning of the class name that describes the condition you want to target. For example, to apply the bg-sky-700class on hover, use the hover:bg-sky-700class:
I found the solution by using play.tailwindcss.com:
This is the syntax I have to use in the tailwind.config.js file:
module.exports = {
purge: [],
theme: {
extend: {},
},
variants: {
opacity: ({ after }) => after(['disabled'])
},
plugins: [],
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With