Responsive Advice Generator built with React, Vite and Tailwind
Design comparison
Solution retrospective
This is my first time using tailwind, I only have 2 questions,
- Is there a way to set the custom styles (e.g colors) using tailwind?
- Which best practices am I missing? Thanks!
Community feedback
- @MelvinAguilarPosted almost 2 years ago
Hello there ๐. Good job on completing the challenge !
I have some feedback for you if you want to improve your code.
-
Is there a way to set the custom styles (e.g colors) using tailwind?
1. In your tailwind.config.js file you can define your own colors using the Tailwind CSS syntax:
Under the extend key in the theme section, add the colors key and their custom colors:
module.exports = { theme: { extend: { // Add the colors key colors: { // Configure your color theme here } } } }
Result:
module.exports = { content: [ "./index.html", "./src/**/*.{js,ts,jsx,tsx}", ], theme: { extend: { colors: { YOUR-CUSTOM-COLOR1: '#00f', YOUR-CUSTOM-COLOR2: '#0f0', primary: '#1fb6ff', secondary: '#334155', }, }, }, variants: {}, plugins: [], }
2. Style your components using Tailwind classes:
<div className="bg-primary text-secondary">Hello World!</div>
You can read more about Customizing Colors here
Other suggestions:
- Adding functionality to non-interactive elements like
div
orimg
is not recommended because they are not designed to be interactive. You should use interactive elements likebutton
to make your elements interactive.
- There is another problem after changing from a div to a button: There isn't much information about what the button is for, and
dice
as thealt
attribute value is not very descriptive, screen reader users will hear "Button, dice" and they won't understand what the button does. You can useGenerate new advice
as thealt
attribute value. You can see an example here.
I hope you find it useful! ๐ Above all, the solution you submitted is great!
Happy coding!
Marked as helpful1 -
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord