Design comparison
Solution retrospective
I need help with two things. The first one is that I don't have an idea of how to create a button with a gradient effect and a color shadow. The second thing is that I read a warning message when I have developed the form, but I don't understand its meaning. Thank u so much to helping me grow :)
Community feedback
- @better5afePosted about 1 year ago
Hi there, nice project!
To answer your questions:
- Gradient background can be implemented with a help of the before or after pseudo element. Since you are using tailwind, add
relative
class to the button and create the pseudo element that will be positioned absolutely to the button and will take up 100% of its height and width, it can be coded inside the index.css file. Add anoverflow-hidden
class to the button or specify the same border radius for the pseudo element, so that the edges are not sticking out. For smooth transition, you can animate its opacity. Also, remember about setting up a higherz-index
value on the button, so that its text will be always visible. - Gradient shadows can also be created using pseudo elements. I encourage you to visit this CSS Tricks article.
- When it comes to the warning message, I think it can be caused by the noRecharge function - it's blocking the default form action but it also returns it at the same time. Try coverting it to this:
export const noRecharge = (event: React.FormEvent<HTMLFormElement> | undefined) => { if (event) { event.preventDefault(); } };
.
Also, I would also suggest to perform the form validation in the function that is triggered on the onSubmit event - this way, the event is always recevied as an argument. The vaiidation check can be performed using a custom hook (here's an example). Based on what it returns, the error state/message can be stored by the useState hook and used to dynamically add classes/style the input element (there's no need to create and render two separate input elements).
Hope it helps!
Marked as helpful1 - Gradient background can be implemented with a help of the before or after pseudo element. Since you are using tailwind, add
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