Dropdown menu on click using only CSS without any JS or other scripts.
Hello Kevin and all the lovely member,
I am facing a challenge to create a menu clickable and not hover using only CSS. This is 1st time asking a query I dont know if its the right channel to post if its not please guide me where to post.
My code:
So its a part of a viewgrid where a table cell carries a dropdown, hover works fine but I want to be able to click and then the menu should open.
Can anyone help me with CSS code depending upon the above classes and Id's used it will highly helpful and greatly appreciated. Thanks.
15 Replies
if you don't want to use js you could do the checkbox trick https://codepen.io/MannixMD/pen/mdGRmVV
Sorry for late response and Thank you very much I will try to replicate this idea.
I cannot get this to work may be I am doing something wrong so we are using a LC/NC platform(Unqork) to build an application
This is the structure of my current code
These are styles applied to the classes
I tried multiple times to get the checkbox trick to replace hover using CSS but failed every time. I tried vanilla JS onclick too but i think the code doesnt accept that.
currently its on hover I want this to be click based
You have two approaches:
1. You use JS
2. You use the label/input trick, where the input "acts" as a fake JS, so the system can recognize you have clicked on it, because there's currently not a "on click" state for CSS (the closest could be
:active
, but this refers to "being clicked" - not just one tap/click).Thank you for the response do we have a code pen for this based on the code structure that we have parent being dropdown div where on hovering the menu opens carrying dropdown-content class.
I tried :active earlier but its a click based as long as mouse key pressed the menu stays open once unlicked the menu disappears.
PS: This is not my code we have just taken over on this project from another team. Any help will be highly appreciated
I highly encourage you for the
input
+ label
alternative.
It uses 0 JS, and it's simple to implement.Web Dev Simplified
YouTube
How To Limit Lines Of Text With CSS Only
Doing vertical text overflow in CSS is incredibly difficult and many people think it is impossible, but that is not true. In this video I will show you 2 different ways to limit the number of lines of text in a box. I will also show you how to expand/collapse those lines of text using only CSS with no JavaScript.
📚 Materials/References:
Kevin...
This shows the technique quite well.
Bro I am really looking forward to you the thing is its not about the table so forget tr's and td's I have posted how the code is right now
probably consider this only
the code is here
I don't think anyone here is going to have any experience with a particular low code no code solution tbh.
Myndi suggested the label / checkbox trick, that's probably your best bet. I can't easily help fix something if I can't see the code running somewhere I can manipulate it, and that's going to be hard using a lc/NC thing. If you can get it to work in a codepen that might help
@allan_1002
I believe the <details> <summary> combo does exactly what you're after and it's also keyboard accessible.
It needs some extra styling (list-type) but you can eventually change the layout of both items however you want and make them look like proper dropdown menus.
You shouldn't use detail and summary for menus, it's an accessibility nightmare
@jochemm you have a source that explains the issues? I'd be interested to learn why and what exactly's causing harm.
AT users I spoke to say "it's ok" and while "unusual" easier to use (presuming proper semantic markup inside) but definitely not worse than most (JS driven) menus they run into in the wild.
Thanks.
not at hand right now, I'll try to look for where I read that in a bit