Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Menu isn´t responsive

I want to make my menu responsive and I found some info on w3school, but I probably made an error. Can you help me with that please? Thanks very much! I am a begginer codes.
If I tried to make the navigation responsive I edited the CSS code and it made the navigation not hidden and the responsive button is showing.

function myFunction() {
  var x = document.getElementById("myTopnav");
  if (x.className === "topnav") {
    x.className += " responsive";
  } else {
    x.className = "topnav";
  }
}
.dropdown .dropbtn {
  font-size: 16px;
  border: none;
  outline: none;
  color: white;
  padding: 14px 16px;
  background-color: inherit;
  font-family: inherit;
  margin: 0;
}

.header {
  overflow: hidden;
  background-color: orange;
  padding: 20px 10px;
}

.header a {
  float: left;
  color: white;
  text-align: center;
  padding: 12px;
  text-decoration: none;
  font-size: 18px;
  line-height: 25px;
  border-radius: 4px;
}

.header a.logo {
  font-size: 25px;
  font-weight: bold;
}

.header a:hover {
  background-color: #ddd;
  color: black;
}

.header a.active {
  background-color: red;
  color: white;
}

.header-right {
  float: right;
}

@media screen and (max-width: 500px) {
  .header a {
    float: none;
    display: block;
    text-align: left;
  }
  .header-right {
    float: none;
  }
}

.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;
  top: 65px;
}

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

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

.dropdown {
  float: left;
  overflow: hidden;
}

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

.dropdown-content:hover {
  display: block
}

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

.hidden {
  display: none;
}

@media screen and (max-width: 600px) {
  .header-right a:not(:first-child) {
    display: none;
  }
  .header-right a.icon {
    float: right;
    display: block;
  }
}

@media screen and (max-width: 600px) {
  .header-right.responsive {
    position: relative;
  }
  .topnav.responsive .icon {
    position: absolute;
    right: 0;
    top: 0;
  }
  .header-right.responsive a {
    float: none;
    display: block;
    text-align: left;
  }
}
<div class="header">
  <a id="txt" hidden></a>
  <img src="https://i.ibb.co/6Nkbdb3/dlhemenu-1-1-1.png" class="logo" title="logo webstránky MENU - www.menu-web.eu" alt="MENU logo" width="150" height="50" onClick="window.location.reload();"> &nbsp
  <a class="dropbtn"><i class="fa fa-user">&nbsp</i>test<?php echo $_SESSION['meno']; ?> 
      <i class="fa fa-caret-down"></i>
    </a>
  <div class="dropdown-content">

    <a href="ucet.php">Môj účet</a>
    <a href="logout.php">Odhlásiť sa</a>

  </div>



  <div class="header-right" id="myTopnav">
    <a class="active" href="/welcome.php">Úvodné menu</a>
    <a href="/online.php">Online hodiny</a>
    <a href="/du.php">Domáce úlohy</a>
    <a href="webcentrum/znamky">Známky</a>
    <a href="/rozvrh.php">Rozvrh hodín</a>
    <a href="/ospravedlnenky.php">Ospravedlnenky</a>
    <a href="/ucenie.php">Učebný materiál</a>
    <a href="javascript:void(0);" class="icon" onclick="myFunction()">
      <i class="fa fa-bars"></i>
    </a>

  </div>
</div>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I read the mistake details carefully.
Please, Try the code following.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .dropdown .dropbtn {
  font-size: 16px;
  border: none;
  outline: none;
  color: white;
  padding: 14px 16px;
  background-color: inherit;
  font-family: inherit;
  margin: 0;
}

.header {
  overflow: hidden;
  background-color: orange;
  padding: 20px 10px;
}

.header a {
  float: left;
  color: white;
  text-align: center;
  padding: 12px;
  text-decoration: none;
  font-size: 18px;
  line-height: 25px;
  border-radius: 4px;
}

.header a.logo {
  font-size: 25px;
  font-weight: bold;
}

.header a:hover {
  background-color: #ddd;
  color: black;
}

.header a.active {
  background-color: red;
  color: white;
}

.header-right {
  float: right;
}

@media screen and (max-width: 500px) {
  .header a {
    float: none;
    display: block;
    text-align: left;
  }
  .header-right {
    float: none;
  }
}

.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;
  top: 65px;
}

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

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

.dropdown {
  float: left;
  overflow: hidden;
}

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

.dropdown-content:hover {
  display: block
}

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

.hidden {
  display: none;
}

@media screen and (max-width: 600px) {
  .header-right a:not(:first-child) {
    display: none;
  }
  .header-right a.icon {
    float: right;
    display: block;
  }
}

@media screen and (max-width: 600px) {
  .header-right.responsive {
    position: relative;
  }
  .topnav.responsive .icon {
    position: absolute;
    right: 0;
    top: 0;
  }
  .header-right.responsive a {
    float: none;
    display: block;
    text-align: left;
  }
}
</style>
<body>
    <div class="header">
        <a id="txt" class="hidden"></a>
        <img src="https://i.ibb.co/6Nkbdb3/dlhemenu-1-1-1.png" class="logo" title="logo webstránky MENU - www.menu-web.eu" alt="MENU logo" width="150" height="50" onClick="window.location.reload();"> &nbsp
        <a class="dropbtn"><i class="fa fa-user">&nbsp</i>test
        <i class="fa fa-caret-down"></i>
        </a>
        <div class="dropdown-content">
        
            <a href="ucet.php">Môj účet</a>
            <a href="logout.php">Odhlásiť sa</a>
        
        </div>
        <div class="header-right" id="myTopnav">
            <a class="active" href="/welcome.php">Úvodné menu</a>
            <a href="/online.php">Online hodiny</a>
            <a href="/du.php">Domáce úlohy</a>
            <a href="webcentrum/znamky">Známky</a>
            <a href="/rozvrh.php">Rozvrh hodín</a>
            <a href="/ospravedlnenky.php">Ospravedlnenky</a>
            <a href="/ucenie.php">Učebný materiál</a>
            <a href="javascript:void(0);" class="icon" onclick="myFunction()">
              <i class="fa fa-bars"></i>
            </a>
        
          </div>
    </div>
</body>
<script>
    function myFunction() {
        var x = document.getElementById("myTopnav");
        if (x.classList.contains("topnav")) {
            x.classList.remove('topnav');
            x.classList.add('responsive');
        } else {
            x.classList.add('topnav');
            x.classList.remove('responsive');
        }
    }
</script>
</html>

Hope it helps little by little.

Thanks.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading