Design comparison
Solution retrospective
Hello guys!
This project was the hardest and longest project that I've ever done ultil now.
I took the liberty of creating a button to the users change their rating, if they want to.
Some problems that I had to figure it out:
1º - The rating buttons are not really buttons. They are an input with "none" display inside a container shaped as button. This way I was able to "hold" the clicked rating in the button! If you have a better solution, tell me please, because it took me more than 5 hours to discover it!
<div>
<input type="radio" name="rating" id="button1" class="checkbox__class" value="1">
<label for="button1">
<div class="container__button"><span>1</span></div>
</label>
</div>
2º - The second problem was to create only 1 hover to change the style of 2 classes. But I didn't manage to do it, so I created 2 codes with one hover for each part:
.redo__button-container:hover .redo__button-text {
color: var(--Orange);
}
.redo__button-container:hover .redo__button {
color: var(--Orange);
}
3° - How to put a transition time when the JavaScript change the styles of the pages?
/* Main page state - here the JS will change the display to none when SUBMIT button is clicked*/
.rating__state {
display: block;
transition: 1s; /* Didn't work, I'll try to fix it with toogle */
}
/* Thank you page state - here the JS will change the display to flex when SUBMIT button is clicked */
.thankyou__state {
display: none;
flex-direction: column;
justify-content: center;
text-align: center;
transition: all 1.5s ease;
}
4º - I used a lot of tags to create the HTML, but I'm not sure if all of them are being used correctly. So, feel free to correct me in all of them!
5º - The JS code! As I'm a beginner, I don't know if I'm using the best paths to get the variables and values. So, if there's a better way to do it, let me know!
var buttons_container = document.getElementsByName("buttons_container")
var submit = document.querySelector("[data-button]")
var place_rating = document.querySelector("[data-rating]")
var mainPage = document.querySelector("[data-mainPage]")
var thanksPage = document.querySelector("[data-thanksPage]")
var redo = document.querySelector("[data-redo]")
submit.addEventListener('click', () => {
getRating ()
changePage ()
})
function getRating () {
let checkbox = document.querySelector('input[name="rating"]:checked');
let rating = checkbox.value
console.log(rating)
place_rating.innerText = rating
}
function changePage () {
mainPage.style.display = "none"
thanksPage.style.display = "block"
}
redo.addEventListener('click', () => {
mainPage.style.display = "block"
thanksPage.style.display = "none"
})
Community feedback
- @Cats-n-coffeePosted almost 2 years ago
Hi Lucas!
Very nice work! I'll try to answer as many of your questions as I can:
- 1 I think radio inputs are appropriate for this problem, good choice! One thought: was the
div
inside thelabel
really necessary? could you add thecontainer__button
class to thelabel
orspan
instead? - 2 Have you tried this?
.redo__button-container:hover .redo__button-text, .redo__button-container:hover .redo__button { color: var(--Orange); }
- 3 I'm not sure I understand this one. Might be a few things to unpack here. If you're trying to toggle classes to change from review to thank you page, using
display: none
is probably going to block you. Maybe this can help? https://stackoverflow.com/questions/3331353/transitions-on-the-css-display-property You can also use@keyframes
for more fancy animations/transitions. Those are all CSS transitions. - 4 In my opinion, you have too many wrapping
div
s. Elements can be on their own and have wrappers for layout purposes/design requirements (images, bg, ...). You should be able to have yoursection
andimg
,h2
,p
andbutton
directly underneath. Only the radio inputs can have a wrapper to make layout easier. - 5 Use
let
orconst
but do not usevar
. Since the arrival oflet
andconst
there is no need to usevar
anymore, it causes headaches and makes your code leaky. You can place all your elements selectors at the top (includingcheckbox
). Try to avoid unnecessary blank lines, and clean up your console logs when you're finished with your project (and commented code, but you don't have any). Great job separating functionality withgetRating
andchangePage
. - 6 Around 760px wide the component, looks really stretched out, maybe add a
max-width
earlier?
Nice work! Hope this helps!
Marked as helpful1@lucasbailoPosted almost 2 years ago@Cats-n-coffee Thanks for the tips!
I'll let this project this way and sooner I'll add the new project correcting all mistakes using your tips!
Your feedback makes me really happy!
0 - 1 I think radio inputs are appropriate for this problem, good choice! One thought: was the
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