Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show/Hide nested list with css

Tags:

html

css

Is there anyway to show and hide onclick a nested list in a vertical navigation sidebar with CSS? if not what would be the best way to do this?

like image 674
thechrishaddad Avatar asked Mar 23 '23 19:03

thechrishaddad


1 Answers

How do you want to hide it? Best is to use simple CSS

ul li ul {
    display: none;
}

ul li:hover ul {
    display: block;
}

You can obviously add some linear transitions/and or fade ins using either CSS or jQuery to avoid the visual jumps.

EDIT

For onClick, use jQuery.

$(".mySelector").click(function() {
    $(this).find("li").find("ul").show();
});

You can replace the show() with fadeIn as well, and I'm assuming by default display: none is there already.

Also, you may wanna use bind if these elements are generated dynamically.

like image 188
J D Avatar answered Mar 29 '23 23:03

J D