Tailwind CSS Autofill and Scrollbar Styling with ShadCN and Dark/Light Mode #14031
DoZ1rN
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
The |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
If you're using ShadCN and implementing dark and light modes in your project, you might have encountered issues with the background color of autofilled input fields. Here's a solution that worked for me, along with custom scrollbar styling.
the solution:
Explanation:
Root Variables for Light Mode:
In the :root selector, I've defined various CSS variables for colors and styles that apply to light mode. These include --background, --foreground, and other utility colors.
Dark Mode Variables:
For dark mode, the same variables are redefined under the .dark class. This allows for easy toggling between light and dark modes by simply adding or removing the .dark class on the root element.
Base Layer Styles:
I've applied some basic styles using Tailwind CSS's @apply directive. This includes setting border colors, body styles, text selection styles, and custom scrollbar styles.
Autofill Input Styling:
The styles for input:-webkit-autofill, textarea:-webkit-autofill, and select:-webkit-autofill ensure that autofilled inputs match the theme's background and text color. The -webkit-box-shadow and box-shadow properties are used to override the default autofill background with the custom --background color.
Custom Scrollbar:
I've customized the scrollbar's width, track color, and thumb color for a more cohesive look that matches the theme.
This setup ensures that your autofill inputs and scrollbars remain consistent with your theme, whether in light or dark mode. If you have any questions or improvements, feel free to comment below!
autofill:text-input
class to ensure the text color and background color are applied only on browser autofill.This setup ensures that your autofill inputs and scrollbars remain consistent with your theme, whether in light or dark mode. The use of CSS variables and the @apply directive from Tailwind CSS makes the styles easy to manage and update. If you have any questions or improvements, feel free to comment below!
Happy coding! 🎨✨
Beta Was this translation helpful? Give feedback.
All reactions