dark: not working in @apply (tailwind 2.0.1) #2917
-
I have some markdown styling in a separate .css file. After upgrading to Tailwind 2.0, I added some
But, the text stays Tailwind version: 2.0.1 I am not sure if some additional configuration/imports are necessary or it is not yet implemented to work with @apply. Kindly support. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 28 comments 37 replies
-
Hey! 👋 Are you sure that the Here's a Tailwind Play example that shows both the https://play.tailwindcss.com/RpfeDooXVs Hope it helps you troubleshoot! |
Beta Was this translation helpful? Give feedback.
-
Hello, Thanks a lot for the response. I copied the same markdown styles to What is the right way to do it? and why does it not work in module.css file? |
Beta Was this translation helpful? Give feedback.
-
I've been able to make it work using nested prefixes ( @layer base {
body {
@apply bg-white;
&.dark {
@apply bg-grey-800;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
I'm also experiencing the issue with my project. Here's an elaborate example of the issue The following code works.index.js ( main js )
global.css
Please note that this is working in index page or the main page only The following code doesn't work.randomElement.js
element.module.css
Please note that this is in another folder /components and used in main js. but this is not working. PS: I tried by adding the following as well and it didn't work. ( I'm using next js ) randomElement.js
|
Beta Was this translation helpful? Give feedback.
-
I am experiencing the same issue with svelte. In media mode, its working but not with class mode. If I am applying direct class, then it works but not with @apply. Applying direct class is not a problem, that can resolved, but when using nested hover I need to use @apply.
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Svelte component example with the same issue: <script>
$: highlightMe = $page.path && $page.path.includes(url) && selectedNav === label ;
</script>
<a class="
text-black
hover:bg-hover
dark:text-white
dark:hover:bg-dark-hover
dark:hover:text-grey
"
class:selected={highlightMe}
href="{url}">
<span class="mx-4 font-medium">{label}</span>
</a>
<style>
.selected {
@apply dark:bg-dark bg-light
}
</style> |
Beta Was this translation helpful? Give feedback.
-
any update? |
Beta Was this translation helpful? Give feedback.
-
We're unable to get this working either thus far |
Beta Was this translation helpful? Give feedback.
-
Actually, we're finding it does work w/Angular and scss, but only if you turn encapsulation off:
Preferably this would also work when using encapsulation. Should we open a new discussion about that specifically? |
Beta Was this translation helpful? Give feedback.
-
Having trouble in 2022 with using the |
Beta Was this translation helpful? Give feedback.
-
For folks using css-modules who land here: #3258 |
Beta Was this translation helpful? Give feedback.
-
I am using Next.js, and seems like // button.module.scss
.button-container {
button {
@apply bg-gray-100 dark:bg-gray-800;
}
} import styles from './button.module.scss';
const Button = () => {
return <div className={styles.buttonContainer}>
<button>{...}</button>
</div>
} |
Beta Was this translation helpful? Give feedback.
-
Hello, mine is not working at all. Whenever I use |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Currently facing the same issues working with tailwind and astro. Even safelisting doesn't solve the problem |
Beta Was this translation helpful? Give feedback.
-
@bhatsudo would you mind re-opening this question or even convert it to an issue? looks like a lot of people have this issue still. i also just stumbled upon this in sveltekit (dark classes not being applied when used with |
Beta Was this translation helpful? Give feedback.
-
I was facing the same issue in Next.JS too. But |
Beta Was this translation helpful? Give feedback.
-
I'm facing the same issue, using astro + svelte + tailwindcss dark only works if parent element have dark class but don't work if html element have it |
Beta Was this translation helpful? Give feedback.
-
I was having the same issue with Next 13.3 and TailwindCSS 3.3, before:
after:
|
Beta Was this translation helpful? Give feedback.
-
I am having the same issue with Nextjs 13.3 |
Beta Was this translation helpful? Give feedback.
-
I found out that when I saved my global.css file in Next.js, the formatter that came with VS Code would automatically format my code and add a space after There is two ways that I found to fix that:
|
Beta Was this translation helpful? Give feedback.
-
I will usually do something like this (in sveltekit)
But of course this is a lot messier than just using |
Beta Was this translation helpful? Give feedback.
-
There is a problem with webpack.config.js import crypto from 'crypto';
const generateScopedName = (localName, resourcePath) => {
if (localName === 'dark') return 'dark'; // <- Do not modify 'dark' class
const getHash = value => crypto.createHash('sha256').update(value).digest('hex');
const hash = getHash(`${resourcePath}${localName}`).slice(0, 4);
return `${localName}--${hash}`;
};
export default {
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: 'css-loader',
options: {
modules: {
getLocalIdent: (context, _, localName) =>
generateScopedName(localName, context.resourcePath),
},
},
},
],
},
],
},
}; |
Beta Was this translation helpful? Give feedback.
-
Hi, Also ran into this issue this week when upgrading tailwind. This used to work in globabls.css and now all of a sudden not.
Package
|
Beta Was this translation helpful? Give feedback.
-
Seeing as a lot of people saying the |
Beta Was this translation helpful? Give feedback.
-
still a problem in 2024 |
Beta Was this translation helpful? Give feedback.
-
As above, still an issue.
I tried this
and this
but nothing. Outline remains white instead of yellow, except if I have
which remains yellow in light theme but is ignored as soon as the theme changes. |
Beta Was this translation helpful? Give feedback.
Hey! 👋
Are you sure that the
dark
class is being applied on a parent element with your custom button implementation? Because what you're describing should definitely work. 👍Here's a Tailwind Play example that shows both the
text-gray-800
andtext-gray-200
styling based on a parent wrapper with adark
class:https://play.tailwindcss.com/RpfeDooXVs
Hope it helps you troubleshoot!