Design comparison
SolutionDesign
Solution retrospective
Hello,
I have problem with black "learn more" button on hover state it adds something that makes top text bouce up. I am not sure for JS code... I think it can be more simplier. Can you please give me any feedback?
Kamil ʕ•́ᴥ•̀ʔっ♡
Community feedback
- @Cats-n-coffeePosted almost 2 years ago
Hi Kamil!
Nice work! I'll give as much feedback as I can:
- the button hover state makes the content jump because you are adding a
border
, which ads to the box (you're essentially adding pixels around the button). I can think of two easy solutions to get around that: 1- add theborder
to the button (before the hover), that way the border is already there when hovering and you only need to change thebackground-color
, 2- useoutline
instead ofborder
on hover since it will add this line inside the button and not outside. Word of caution with this second one, sinceoutline
is there by default onfocus
, it's actually an important state that should be modified carefully/be a distinct state in most cases (in your case you'll modify the color, which might make it the same as hover and that's not a good solution, ... but it's good to know it's possible). - your font doesn't seem to have loaded correctly, or you not have it imported anywhere, I can't find it in your HTML or Css.
- around 1194px width your title is stuck at the very top of the page, which might be because of your layout and the
height
you're calculating. If you're using flexbox, you should be able maintain all elements within their space by using wrappers (div
s) and setting theflex-direction
andflex
properties. - your chevrons (near the menu items) appear broken on my machine (using FF), and the dropdown menus are missing styles.
- adding an click listener to the
document
and matching the event target is a valid way, but might not be the simplest way in your case. You could just declare all your elements at the top and place an event listener on each. Since your logic is the same across (adding theactive
class) you can create a single function for this. If you want to keep track of the current dropdown, take the variable out in the global scope, that way it can accessed everywhere, and you can make a separate function to remove the class. You could also have one event listener per menu item and loop through their child elements to place more event listeners if you'd like. That way you don't need to grab every single submenu item in a separate variable (so you'll do aforEach
like you did). - in general, try avoiding having callbacks inside of callbacks like you're doing with
document.querySelectorAll
, Js can easily get you down this "callback hell" and your code will get difficult to deal with.
Good job! Hope this helps, let me know if your have any questions!
Marked as helpful0 - the button hover state makes the content jump because you are adding a
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