responsiveness problem with "Menu" button in navbar

Viewed 53

I'm building a website and I want to make it more responsive, currently I just need to make the navbar responsive, but I'm having problems with that, especially with the "Menu" button, when I make the screen smaller, the "Menu" button is under the navbar, could anyone help me? (if you need to see the site, I've already put it on Github Pages:

https://eduardwildneto.github.io/ConversorDeUnidades/),

this is my code:

.navbar {
  background: rgb(6, 0, 206);
  color: rgb(0, 0, 0);
  padding: 1px;
  max-height: 55px;
  margin-bottom: 10px;
  position: sticky;
  font-size: 20x;
  z-index: 999;
  top: 0px;
  position: sticky;
}

.navbar ul {
  list-style: none;
  padding: 0;
}

.navbar ul li {
  display: inline;
}

.navbar ul li a {
  display: inline;
  color: white;
  text-decoration: none;
  padding: 15px;
  display: inline-block;
  margin: auto;
}

#dominio-principal {
  padding-left: 10%;
  padding-right: 61%;
  font-size: 18px;
}

#outros-dominios-1 {
  float: left;
  font-size: 15px;
}

#outros-dominios {
  font-size: 15px;
  padding-left: 1px;
}


/*.navbar {
    background: rgb(6, 0, 206);
    color: white;
    font-size: 20px;
    padding: 1%;
    min-height: 65px;
}

.navbar ul {
    list-style: none; 
}

.navbar ul li {
    display: inline;
}

.navbar ul li:last-child {
    float: right; 
    margin-right: 4%;
}

.navbar ul li a {
    color: white;
    text-decoration: none;
}

#dominio-principal {
    font-size: 18px;
    position: absolute;
}
 

#outros-dominios-1 {
    padding-left: 406px;
    font-size: 15px;
}

#outros-dominios {
    font-size: 15px;
    padding-left: 1px;
}*/


/*Dropdown*/

.dropbtn {
  background-color: rgb(6, 0, 206);
  padding: 16px;
  font-size: 16px;
  border: none;
  cursor: pointer;
  z-index: 999;
  color: white;
}


/* Dropdown button on hover & focus */

.dropbtn:hover,
.dropbtn:focus {
  background-color: rgb(6, 0, 206);
  z-index: 999;
}


/* The container <div> - needed to position the dropdown content */

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


/* Dropdown Content (Hidden by Default) */

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


/* Links inside the dropdown */

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


/* Change color of dropdown links on hover */

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


/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */

.show {
  display: block;
  z-index: 999;
}
<header>
  <nav class="navbar">
    <ul>
      <li><a href="" id="dominio-principal">Conversor de Unidades</a></li>
      <div class="dropdown">
        <button onclick="dropdown()" class="dropbtn">Menu</button>
        <div id="myDropdown" class="dropdown-content">
          <a href="index.html">Distância</a>
          <a href="">Peso (Em construção)</a>
          <a href="">Área (Em construção)</a>
          <a href="">Volume (Em construção)</a>
          <a href="">Temperatura (Em construção)</a>
          <a href="">Tempo (Em construção)</a>
          <a href="">Dados (Em construção)</a>
        </div>
      </div>
    </ul>
  </nav>
</header>

1 Answers

Try using flexbox to make your navbar responsive. For reference visit https://www.w3schools.com/css/css3_flexbox.asp

To start using Flexbox, you need to first define a flex container .navbar ul in your css file style.css :

You can change it :

.navbar ul {
  list-style: none;
  padding: 0 10%; /*To adjust left & right navbar padding*/
  display: flex;
  justify-content: space-between; /*or space-around*/
}

After that you can change the children element #dominio-principal:

#dominio-principal {
  /*
  padding-left: 10%;
  padding-right: 61%;
  */
  font-size: 18px;
}

Related