We can use the theme()
function and the darkMode
property in the tailwind.config.js
file to implement styling that depends on whether the mode is light or dark.
Here is an example of how to do this:
// tailwind.config.js
module.exports = {
darkMode: 'class',
theme: {
extend: {
colors: {
primary: theme => ({
light: theme('colors.blue.500'),
dark: theme('colors.green.500'),
}),
},
},
},
};
In this example, we have set the darkMode
property to 'class'
, which means that we will use the CSS class dark
to switch between light and dark modes.
Next, we define a custom color called primary
, which has different values depending on the mode. We use the theme()
function to access the colors defined in Tailwind CSS, and we use the dark
property to define the dark mode color.
Finally, we can use this custom color in our CSS by referencing it with the text-primary-light
and text-primary-dark
classes:
<!-- HTML -->
<h1 class="text-primary-light dark:text-primary-dark">Hello World!</h1>
In this example, the text color will be blue in light mode and green in dark mode.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-03-19 11:00:00 +0000
Seen: 9 times
Last updated: Jun 19 '22
What is the procedure for using Pandas fillna() method with the column's mode?
How can I avoid undesirable stretching when using Unity in orthographic mode?
What is the method for accessing the info mode in Emacs to open a *.info file?
What are the steps to implement dark mode and merge two distinct web pages into a single one?
Can Selenium be executed on a cloud platform with headless mode enabled?
How can a newline be added in vim without entering insert mode?
How can we implement a dark mode using jQuery on an HTML page?
Is it true that the SPM UIColor resources are incompatible with Dark mode?
What is the procedure to modify the light/dark mode icon in Docusaurus?