html – My dropdown navbar is going crazy and I can't explain why-ThrowExceptions

Exception or error:

I recently started working on a friend motoring school website project. I had done an HTML/CSS dropdown on hover navbar to show every formation my friend was able to give. But, I don’t know how and why , it started going crazy and now everything is weird as you could see if you try my code. I tried everything but nothing seems to solve it.

So I created an account on this website that helped me numerous times. Here is my html code and css code so that you may be helping me:

header {
  margin-left: 10px;
  margin-right: 10px;
  margin-top: 5px;
  padding: 0;
  position: relative;
  height: 200px;
  background: #EFEFEF;
}

body {
  margin: 0px;
  padding: 0px;
  font-family: 'Source code pro', Calibri, Serif;
  background: #EFEFEF;
}

.black {
  height: 60px;
  background: black;
  width: 100%;
  color: #ff00ff;
  position: absolute;
  bottom: 0;
}

nav>ul {
  margin: 0px;
  padding: 0px;
}

nav li {
  list-style: none;
}

nav>ul>li {
  position: relative;
  float: left;
}

.sub-menu {
  display: none;
}

nav>ul::after {
  content: "";
  display: block;
  clear: both;
}

nav a {
  display: inline-block;
  text-decoration: none;
}

nav>ul>li>a {
  padding: 20px 30px;
  color: #FFF;
}

nav li:hover .sub-menu {
  display: inline-block;
  background-color: red;
  position: absolute;
  top: 100%;
  left: 0px;
  padding: 0px;
  z-index: 1000;
}

ul li ul .item-2 {
  position: absolute;
  left: 120px;
}

.sub-menu li {
  border-bottom: 2px solid #ff00ff;
}

.sub-menu li a {
  font-size: 13px;
  padding: 15px 30px;
  color: black;
  width: 150px;
}

.permis-auto:hover,
.permis-moto:hover,
.permis-remorque:hover,
.code:hover,
.info:hover {
  border-top: 1px solid grey;
  color: #ff00ff;
  background: #ff00ff;
}

.permis-auto:hover,
.permis-moto:hover,
.permis-remorque:hover,
.code:hover,
.info:hover .presentation {
  margin-top: 100px;
}

.sub-menu:hover {
  background: rgb(255, 0, 255, 0.30);
  color: white;
}

.sous-onglet {
  display: none;
}

.presentation {
  margin-left: 10px;
  margin-right: 10px;
  margin-top: 50px;
  border: 3px solid black;
  height: 300px;
  background: #EFEFEF;
  display: flex;
  justify-content: space-around;
}

.container {
  border: 3px solid #ff00ff;
  margin-top: 5px;
  margin-bottom: 5px;
  width: 45%;
  position: relative;
}

.container>img {
  height: 100%;
  width: 100%;
}

.floatleft {
  float: left;
}

.logo {
  width: 18%;
  margin-top: 5px;
  display: block;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 10px;
}

marquee {
  color: #ff00ff;
}

.text-block {
  position: absolute;
  bottom: 0px;
  right: 0px;
  background-color: black;
  color: white;
  height: 90px;
  text-align: center;
  width: 100%;
  opacity: 0;
}

.container:hover .text-block {
  opacity: 0.75;
}

.slider {
  border: 3px solid #ff00ff;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
  width: 50%;
  height: 50%;
  overflow: hidden;
  position: relative;
  margin-top: 15px;
}

#img img {
  animation: ani 2s linear;
  width: 100%;
  height: 100%;
}

@keyframes ani {
  0% {
    transform: scale:(1.2);
  }
  10% {
    transform: scale:(1);
  }
  100% {
    transform: scale:(1);
  }
}

.mySlides {
  display: none;
}

.slideshow-container {
  max-width: 1000px;
  position: relative;
  margin: auto;
}


/* Caption text */

.text {
  color: #f2f2f2;
  font-size: 15px;
  padding: 8px 12px;
  position: absolute;
  bottom: 8px;
  width: 100%;
  text-align: center;
}


/* Number text (1/3 etc) */

.numbertext {
  color: #f2f2f2;
  font-size: 12px;
  padding: 8px 12px;
  position: absolute;
  top: 0;
}


/* The dots/bullets/indicators */

.dot {
  height: 15px;
  width: 15px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}

.active {
  background-color: #717171;
}


/* Fading animation */

.fade {
  -webkit-animation-name: fade;
  -webkit-animation-duration: 1.5s;
  animation-name: fade;
  animation-duration: 1.5s;
}

@-webkit-keyframes fade {
  from {
    opacity: .4
  }
  to {
    opacity: 1
  }
}

@keyframes fade {
  from {
    opacity: .4
  }
  to {
    opacity: 1
  }
}


/* On smaller screens, decrease text size */

@media only screen and (max-width: 300px) {
  .text {
    font-size: 11px
  }
}

.avis {
  line-height: 14px;
  margin-left: 10px;
  margin-right: 10px;
  margin-top: 15px;
}

input,
select,
textarea {
  border: 1px solid #ff00ff;
}

.left {
  float: left;
}

.icon {
  position: relative;
  left: 10px;
  width: 18%;
  height: 18%;
  width: 50px;
  margin-top: 5px;
  display: block;
  background-color: #ff00ff;
  margin-bottom: 10px;
}

.facebookkk {
  text-align: center;
  background: #ff00ff;
  color: white;
  width: 50%;
  margin-right: auto;
  margin-left: auto;
}

.tt {
  color: black;
  text-align: center;
}

.separer {
  justify-content: center;
  display: flex;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<body>
  <header><img src="logo 3.jpg" alt="" class="logo" style="height:80px;width:350px" />
    <marquee>Bienvenue sur le site de l'auto école Berthier</marquee>
    <div class="black">
      <nav>
        <ul>
          <li class="info"><a href="index.php">ACCUEIL</a></li>
          <li class="permis-auto"><a href="auto.html">MOTO</a>
            <ul class="sub-menu" style="background: rgb(255, 0, 255, 0.30)">

              <li class="permis-auto" id="testid" style="text-align:center"><a href="auto.html" style="font-size:20px"><i><b>PERMIS </br>AM</a>
                <ul class="sous-onglet" id="bute" style="position:absolute;left:169px;bottom:80%">
                  <li class="sous-onglet" style="color:green"><a href="infoam.html"><b><i>INFOS</a></li>
                  <li><a href="tarifam.html">TARIFS</a></li>
                  </b>
                  </i>
                </ul>
              </li>

              <li class="permis-auto" id="testid2" style="text-align:center"><a href="125.html" style="font-size:20px">FORMATION 125</a>
                <ul id="bute2" style="position:absolute;left:169px;bottom:59.8%">
                  <li><a href="125info.html">INFOS</a></li>
                  <li><a href="tarif125.html">TARIFS</a></li>
                </ul>

              </li>
              <li class="permis-auto" id="testid3" style="text-align:center"><a href="auto.html" style="font-size:20px">PERMIS</br> A1</a>
                <ul id="bute3" style="position:absolute;left:169px;bottom:40%">
                  <li><a href="a1info.html">INFOS</a></li>
                  <li><a href="a1tarif.html">TARIFS</a></li>
                </ul>

              </li>
              <li class="permis-auto" id="testid4" style="text-align:center"><a href="auto.html" style="font-size:20px">PERMIS </br>A2</a>
                <ul id="bute4" style="position:absolute;left:169px;bottom:20%">
                  <li style="height=20px"><a href="a2info.html">INFOS</a></li>
                  <li style="height=20px"><a href="a2tarif.html">TARIFS</a></li>
                </ul>

              </li>
              <li class="permis-auto" id="testid5" style="text-align:center"><a href="a2versa.html" style="font-size:20px">PASSERELLE </br>A2-A</a>
                <ul id="bute5" style="position:absolute;left:169px;bottom:0;">
                  <li><a href="a2versainfo.html">INFOS</a></li>
                  <li><a href="a2versatarif.html">TARIFS</a></li>
                </ul>

              </li>
            </ul>
          </li>
          </b>
          </i>
          <li class="permis-moto"><a href="auto.html">AUTO</a>
            <ul class="sub-menu" style="background: rgb(255, 0, 255, 0.30)">

              <li class="permis-auto" id="autoid" style="text-align:center"><a href="tarifsauto.html" style="font-size:20px"><b><i>PERMIS</br> B</a>
                <ul id="auto" style="position:absolute;left:169px;bottom:72.7%;">
                  <li><a href="infob.html">INFOS</a></li>
                  <li><a href="tarifsauto.html">TARIFS</a></li>
                </ul>
              </li>
              <li class="permis-auto" id="autoid2" style="text-align:center"><a href="tarifsconduite.html" style="font-size:20px">CONDUITE ACCOMPAGNEE</a>
                <ul id="auto2" style="position:absolute;left:169px;bottom:45.5%">
                  <li><a href="infoconduite.html">INFOS</a></li>
                  <li><a href="tarifsconduite.html">TARIFS</a></li>
                </ul>

              </li>
              <li class="permis-auto" id="autoid3" style="text-align:center"><a href="auto.html" style="font-size:20px">CONDUITE SUPERVISEE</a>
                <ul id="auto3" style="position:absolute;left:169px;bottom:18.3%;">
                  <li><a href="infosupervisee.html">INFOS</a></li>
                  <li><a href="tarifsupervisee.html">TARIFS</a></li>
                </ul>

              </li>
              <li class="permis-auto" style="text-align:center"><a href="perfectionnement.html" style="font-size:18px">PERFECTIONNEMENT</a> </li>
            </ul>
          </li>
          </b>
          </i>
          <li class="permis-remorque"><a href="auto.html"> REMORQUE</a>
            <ul class="sub-menu" style="background: rgb(255, 0, 255, 0.30)">

              <li class="permis-auto" id="remorqueid" style="text-align:center"><a href="auto.html" style="font-size:20px"><b><i>PERMIS </br>BE</a>
                <ul id="remorque" style="position:absolute;left:169px;bottom:50%;">
                  <li><a href="beinfo.html">INFOS</a></li>
                  <li><a href="beinfo.html">TARIFS</a></li>
                </ul>

              </li>
              <li id="remorqueid2" class="permis-auto" style="text-align:center"><a href="b96.html" style="font-size:20px">FORMATION B96</a>
                <ul id="remorque2" style="position:absolute;left:169px;bottom:0;">
                  <li><a href="b96info.html">INFOS</a></li>
                  <li><a href="b96tarifs.html">TARIFS</a></li>
                </ul>
              </li>
            </ul>
          </li>
          </b>
          </i>
          <li class="code"><a href="prestations.html">PRESTATIONS A L'UNITÉ</a>
            <ul class="sub-menu" style="background: rgb(255, 0, 255, 0.30);width:270px;text-align:center">
              <li class="permis-auto"><a href="prestationscode.html" style="font-size:20px"><b><i>CODE</b></i></a>
                <li class="permis-auto"><a href="prestations.html" style="font-size:20px"><b><i>VOITURE</a> </li>
                <li class="permis-auto"><a href="prestationsmoto.html" style="font-size:20px">MOTO</a> </li>
                <li class="permis-auto"><a href="prestationsremorque.html" style="font-size:20px">REMORQUE</a> </li>
                <li class="permis-auto"><a href="prestationspapeterie.html" style="font-size:20px">PAPETERIE</a>

                </li>
                </b>
                </i>
            </ul>
            </li>
          </li>

          <li class="info"><a href="auto.html">COMPOSITION DOSSIER</a>
            <ul class="sub-menu" style="background: rgb(255, 0, 255, 0.30)">

              <li class="permis-auto"><a href="dossiera1a2.html" style="font-size:20px"><b><i>PERMIS A1/A2</a> </li>
              <li class="permis-auto"><a href="permisb.html" style="font-size:20px">PERMIS AUTO</a> </li>
              <li class="permis-auto"><a href="conduiteacc.html" style="font-size:20px">CONDUITE ACCOMPAGNEE</a> </li>
              <li class="permis-auto"><a href="dossierremorque.html" style="font-size:20px">REMORQUE</a>
                <ul style="position:absolute;left:165px;top:70;display:none">
                  <li><a href="#">A</a></li>
                  <li><a href="#">A</a></li>
                  <li><a href="#">A</a></li>

                </ul>
              </li>
              <li class="permis-auto"><a href="dossieraam125.html" style="font-size:20px">A,AM,125cm<sup>3</sup></a> </li>

            </ul>
          </li>
          </b>
          </i>

          <li class="info"><a href="contact.html">NOUS CONTACTER</a></li>
          <li class="info"><a href="auto.html">+ D'INFOS</a>
            <ul class="sub-menu" style="background: rgb(255, 0, 255, 0.30)">

              <li class="permis-auto"><a href="avis.php" style="font-size:20px;text-align:center"><b><i>AVIS</a> </li>
              <li class="permis-auto" style="text-align:center"><a href="horairesbureau.html" style="font-size:20px">HORAIRES BUREAU</a> </li>
              <li class="permis-auto" style="text-align:center"><a href="horairescode.html" style="font-size:20px">HORAIRES CODE</a> </li>
              <li class="permis-auto" style="text-align:center"><a href="pisteauxmotos.html" style="font-size:20px">PISTE AUX MOTOS</a> </li>
              <li class="permis-auto" style="text-align:center"><a href="horairescode.html" style="font-size:20px">PLATEAUX</a> </li>
            </ul>
          </li>
          </b>
          </i>

        </ul>
      </nav>
    </div>
  </header>

I’m sorry, it isn’t responsive nor great looking to read.

How to solve:

I am providing this link for reference the way you want your drop list to work is implemented over here.Link : https://www.w3schools.com/css/css_dropdowns.asp. I hope it will help you.
enter image description here

You can just refer this code and execute it in your local system.

<!DOCTYPE html>
<html>
<head>
<style>
.dropbtn {
 background-color: #4CAF50;
 color: white;
 padding: 16px;
 font-size: 16px;
 border: none;
 cursor: pointer;
 }

 .dropdown {
  position: relative;
  display: inline-block;
  }

 .dropdown-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
  }

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

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

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

.dropdown:hover .dropbtn {
 background-color: #3e8e41;
 }
 </style>
</head>
<body>

<h2>Dropdown Menu</h2>
<p>Move the mouse over the button to open the dropdown menu.</p>

<div class="dropdown">
  <button class="dropbtn">Dropdown</button>
  <div class="dropdown-content">
    <a href="#">Link 1</a>
    <a href="#">Link 2</a>
    <a href="#">Link 3</a>
  </div>

<p><strong>Note:</strong> We use href="#" for test links. In a real web site this would be URLs.</p>

</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *