Multi-level dropdown menu

Hi everyone! So…i have this drop down menu and i want to make a multi-level drop on some links.
For exemple, at Produse Informative CIMICEstimare Cimic i want to show another menu with 2 links from Estimare Cimic called Studii judete and Studii mari.

this is the HTML:

<ul id="menu">
	<li class="dropdown"><a href="../index.html" class="dropbtn">Home</a>
		<div class="dropdown-content">
      		        <a href="../buletin.html">Buletin Informativ CIMIC</a>
      			<a href="../despre.html">Despre CIMIC</a>
      			<a href="../contact.html">Contact</a>
		</div>
	</li>

	<li class="dropdown"><a style="cursor:pointer" class="dropbtn">Instrucție și Educație CIMIC</a>
		<div class="dropdown-content">
      			<a href="../exercitii.html">Exerciții</a>
      			<a href="../instructiecmdt.html">Instrucție de comandament</a>
      			<a href="../proceduri.html">Proceduri Operaționale</a>	
      			<a href="../lectii.html">Lecții învățate</a>
		</div>
	</li>

	<li class="dropdown"><a style="cursor:pointer" class="dropbtn">Produse Informative CIMIC</a>
		<div class="dropdown-content">
      			<a href="../ccir.html">CCIR CIMIC</a>
      			<a href="../cimicrep.html">CIMIC REP</a>
      			<a href="../evaluare.html">Evaluare mediul civil</a>	
      			<a href="../estimare.html">Estimare CIMIC</a>
      			<a href="../studiireg.html">Studii regiune</a>
      			<a href="../studii.html">Studii țară</a>
		</div>
	</li>

	<li class="dropdown"><a style="cursor:pointer" class="dropbtn">Relaționare Interinstituțională</a>
		<div class="dropdown-content">
      			<a href="../autoritati.html">Autorități</a>
      			<a href="../saopsn.html">Instituții SAOPSN</a>
      			<a href="../institutii.html">Instituții de învățământ</a>	
      			<a href="../institutiiciv.html">Alte instituții civile</a>
      			<a href="../organizatii.html">Organizații civile</a>
		</div>
	</li>

	<li class="dropdown"><a style="cursor:pointer" class="dropbtn">e-CIMIC library</a>
		<div class="dropdown-content">
      			<a href="../glosar.html">Glosar</a>
      			<a href="../doctrinenato.html">Doctrine, Manuale CIMIC NATO</a>
      			<a href="../doctrine.html">Doctrine, Manuale CIMIC Naționale</a>	
      			<a href="../publicatii.html">Publicații de interes</a>
      			<a href="../cultural.html">CULTURAL AWARENESS</a>
      			<a href="../sites.html">CIMIC sites</a>
		</div>
	</li>
</ul>

and this is the CSS

li a, .dropbtn 
{
    display: inline-block;
    color: blue;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

li a:hover, .dropdown:hover .dropbtn 
{
    background-color: none;
}

li.dropdown {
    display: inline-block;
}

.dropdown-content 
{
    display: none;
    position: absolute;
    background-color: #BDBDBD;
    min-width: 70px;
    box-shadow: 5px 5px 5px 5px ;
    z-index: 1;
}

.dropdown-content a 
{
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
}

.dropdown-content a:hover 
{
background-color: #f1f1f1;

}

.dropdown:hover .dropdown-content {
    display: block;
}

Hi,

To add another level is more or less the same as you have done for the first level except that for the second level you show the dropdown to the right of the trigger rather than underneath.

Usually with dropdowns like this you would use nested lists as that is more semantic than using a nested div and also easier to target without using multiple classes. You can target the first level only using the child selector (>) and avoid triggering nested levels by accident.

Another point for accessibility is that hiding with display:none is not very accessible for screen readers (and some search engines) so you are better moving the menu off screen and then bring it back on screen when needed. This means that the links are always available to screen readers and search engines etc. It also has the added benefit that you can then add a little transition effect if you want because you can’t animate from display:none.

Also be careful with styling elements directly like li a {} etc. It is highly unlikely that you want all lists throughout your site styled as dropdowns so vene when making demos use a class to base the styles on. e.g. .menu li a{}

Have a look at a basic multiple drop down that I have set up from another similar thread that has all those points in mind.

You should be able to use that to modify your own code quite easily. If you get stuck then post what you have tried and I will offer more specific advice.

Bear in mind that dropdowns are not very mobile/touch friendly or easily accessed by those with motor disabilities.

EDIT:

OK I had a few minutes so here’s a start:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Untitled Document</title>
<style>
ul {
	margin:0;
	padding:0;
	list-style:none;
}
.menu a {
	display: inline-block;
	color: blue;
	text-align: center;
	padding: 14px 16px;
	text-decoration: none;
}
li.dropdown {
	display: inline-block;
	position:relative;
}
.dropdown:hover > a {
	background:#f1f1f1;
}
.dropdown-content {
	position: absolute;
	background-color: #BDBDBD;
	min-width: 70px;
	box-shadow: 5px 5px 5px 5px;
	z-index: 1;
	top:0;
	left:-999em;
	transition:top .5s ease;
}
.dropdown-content li {
	display:block;
}
.dropdown-content a {
	color: black;
	padding: 12px 16px;
	text-decoration: none;
	display: block;
	text-align: left;
}
.dropdown-content a:hover, .dropdown-content li:hover > a {
	background-color: #f1f1f1;
}
.dropdown:hover > .dropdown-content {
	left:0;
	top:100%;
}
.dropdown .dropdown > .dropdown-content {
	transition:transform .5s ease, opacity .3s ease;
	transform:translateX(-100%);
	opacity:0;
}
.dropdown .dropdown:hover > .dropdown-content {
	left:100%;
	transform:translateX(0);
	top:0;
	opacity:1;
}
</style>
</head>

<body>
<ul id="menu" class="menu">
  <li class="dropdown"><a href="#" class="dropbtn">Produse Informative CIMIC</a>
    <ul class="dropdown-content">
      <li><a href="../ccir.html">CCIR CIMIC</a></li>
      <li><a href="../cimicrep.html">CIMIC REP</a></li>
      <li><a href="../evaluare.html">Evaluare mediul civil</a></li>
      <li class="dropdown"><a href="../estimare.html">Estimare CIMIC</a>
        <ul class="dropdown-content">
          <li><a href="../estimare.html">Studii judete</a>
          <li><a href="../estimare.html">Studii mari.</a>
        </ul>
      </li>
      <li><a href="../studiireg.html">Studii regiune</a></li>
      <li><a href="../studii.html">Studii țară</a></li>
    </ul>
  </li>
  <li class="dropdown"><a href="#" class="dropbtn">Produse Informative CIMIC</a>
    <ul class="dropdown-content">
      <li><a href="../ccir.html">CCIR CIMIC</a></li>
      <li><a href="../cimicrep.html">CIMIC REP</a></li>
      <li><a href="../evaluare.html">Evaluare mediul civil</a></li>
      <li class="dropdown"><a href="../estimare.html">Estimare CIMIC</a>
        <ul class="dropdown-content">
          <li><a href="../estimare.html">Studii judete</a>
          <li><a href="../estimare.html">Studii mari.</a>
        </ul>
      </li>
      <li><a href="../studiireg.html">Studii regiune</a></li>
      <li><a href="../studii.html">Studii țară</a></li>
    </ul>
  </li>
</ul>
</body>
</html>

I’ve just duplicated the menu items twice for testing but you would need to follow the same format for all the items as required. I’ve also left your classes in place but a lot are really redundant in that structure.

that helped me. Thank you very much for your answer,i will try to make it better. Greetings

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.