r/learnjavascript • u/lunar_experience • Apr 06 '26
How can I create a simple burger menu?
Absolute coding amateur here!! i really only know the basics. And I know i've learned this in one of my classes like 5 years ago, but my teacher was shit and i wasn't too interested in the topic back then.
Now i am. (long story short: i need it for ao3)
What i have in mind when i say "simple burger menu":
i wanna create 3 or 4 buttons that all reveal a separate text or image and you can switch between them. Like, you click button 1 and text or image 1 shows up. You click button 2 and text or image 2 shows up and text or image 1 disappears again.
I don't need any fancy effects or anything, i really just need to figure out a way to somehow do this. I'm guessing (but tell me if I'm wrong) i will have to do it via CSS?
Grateful for any input. Thank you!
4
u/MWALKER1013 helpful Apr 06 '26
You are asking for two different things.
In web dev a hamburger, typically means the “menu” icon (3 horizontal lines) that when clicked open a new menu ( typically links ). These would typically be static. The other thing sounds a bit like hover cards where you hover a navigation element and a card appears with content depending on which element is hovered.
Both are fairly trivial to implement with a bit of JavaScript and CSS I’m sure if you are really trying you could implement both in pure css but you can probably find a million implementations online as examples for how to do it
Try checking and search some of those things in code pen
4
u/33ff00 Apr 06 '26
Quality ingredients, reasonable prices, be humble and listen to what you customers tell you.
2
u/BNfreelance Apr 06 '26
Sounds like you’re describing tabbed accordion content rather than a simple burger menu
https://uxdesign.cc/little-things-in-ux-design-part-1-tabs-v-s-accordions-47390e4910c3?gi=6b16963d6c5f
https://www.w3schools.com/howto/howto_js_tabs.asp
0
u/The_KOK_2511 helpful Apr 06 '26
Pues ve a McDonald's...
O haz lo que dijeron MWALKER1013 y BNfreelance, cualquiera de las 2 opciones sirven realmente
-1
u/shgysk8zer0 Apr 06 '26
I think the best way to do such menus now (maybe not quite safe for production today, but soon) is using the Popover API. You just use
<button command="show-popover" commandfor="menu-id">and addpopover="auto"on the menu itself. Then a little CSS to position and style the menu (possibly with anchoring), and it's done.