Title not staying at the top left when hamburguer buttons shows up

Viewed 50

Don't really know why this is happening my title "Roberto Salas" it's not staying in place when I change the window size, also doesn't stay in place when I open it on my cellphone title not in right position

Title not in right position when the hmb button drops

I would like that the title stay in the top left heres my code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Roberto Salas</title>
  <link rel="stylesheet" href="style.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
  <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
  <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300&display=swap" rel="stylesheet"> 
</head>
<body>
  <div class="wrapper">
    <header>
      <nav>
        <div class="menu-icon">
          <i class="fa fa-bars fa-2x"></i>
        </div>

        <div id="Title" class="name">Roberto Salas</div>

        <div class="Monse">
          <ul >
            <li><a href="#" class="submenu2" >Home</a></li>
            <li><a href="#" class="submenu2" >About</a></li>
            <li><a href="#" class="submenu2" >Blog</a></li>
            <li><a href="#" class="submenu2">Contact</a></li>
          </ul>
        </div>
      </nav>
    </header>

    <div class="content">
      <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
      <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    </div>
  </div>

  <script type="text/javascript">
    // Menu-toggle button
    $(document).ready(function() {
      $(".menu-icon").on("click", function() {
        $("nav ul").toggleClass("showing");
        $('#Title').addClass('name2');
        $('a').css('color','white');
      });
    });

    // Scrolling Effect
    $(window).on("scroll", function() {
      if($(window).scrollTop()) {
        $('nav').addClass('black');
        $('#Title').addClass('name2');
        $('a').css('color','white');
      }

      else {
        $('nav').removeClass('black');
        $('#Title').removeClass('name2');
        $('a').css('color','black');
      }
    })
  </script>
</body>
</html>

Here is my style sheet

 html, body {
      margin: 0;
      padding: 0;
      width: 100%;
}
.Monse{
    letter-spacing: 2px;
      font-family: 'Montserrat', sans-serif;
}



body {
      font-family: "Helvetica Neue",sans-serif;
      font-weight: lighter;
}

header {
      width: 100%;
      height: 100vh;
  background: url(img/bosqueaves.jpg) no-repeat center;
      background-size: cover;
}



.content {
      width: 94%;
      margin: 4em auto;
      font-size: 20px;
      line-height: 30px;
      text-align: justify;
}


.name{
      line-height: 60px;
      position: fixed;
      float: left;
      margin: 16px 46px;
      color: black;
      font-size: 20px;
      letter-spacing: 2px;
      font-family: 'Montserrat', sans-serif;
}

.name2{
    line-height: 60px;
      position: fixed;
      float: left;
      margin: 16px 46px;
      color: white;
      font-size: 20px;
      letter-spacing: 2px;
      font-family: 'Montserrat', sans-serif;

}

.smenu{
    text-decoration: none;
      font-size: 16px;
    color: white;
}

.submenu2{
     text-decoration: none;
      font-size: 16px;
    color: black;
}




nav {
          position: fixed;
          width: 100%;
          line-height: 60px;
    }



nav ul {
      line-height: 60px;
      list-style: none;
      background: rgba(0, 0, 0, 0);
      overflow: hidden;
      padding: 0;
      text-align: right;
      margin: 0;
      padding-right: 40px;
      transition: 1s;
      text-decoration: none;

}

nav.black ul {
      background: #000;
    text-decoration: none;

}

nav ul li {
      display: inline-block;
      padding: 16px 40px;;
    text-decoration: none;

}




      .menu-icon {
              line-height: 60px;
              width: 100%;
              background: #000;
              text-align: right;
              box-sizing: border-box;
              padding: 15px 24px;
              cursor: pointer;
              color: white;
              display: none;
        }



 @media(max-width: 786px) {

          .logo {
                position: fixed;
                top: 0;
                margin-top: 16px;
          }

          nav ul {
                max-height: 0px;
                background: #000;
              text-decoration: none;
          }

          nav.black ul {
                background: #000;
              text-decoration: none;
          }

          .showing {
                max-height: 34em;
          }

          nav ul li {
                box-sizing: border-box;
                width: 100%;
                padding: 24px;
                text-align: center;
              text-decoration: none;
          }

          .menu-icon {
                display: block;
          }

    }

you can also check the website at https://gonzaloalcala.github.io/ProyectoR/index.html

3 Answers

add to your css nav{display:flex; flex-direction:column;} `

nav{display:flex;
flex-direction:column;}
Here is my style sheet

 html, body {
      margin: 0;
      padding: 0;
      width: 100%;
}
.Monse{
    letter-spacing: 2px;
      font-family: 'Montserrat', sans-serif;
}



body {
      font-family: "Helvetica Neue",sans-serif;
      font-weight: lighter;
}

header {
      width: 100%;
      height: 100vh;
  background: url(img/bosqueaves.jpg) no-repeat center;
      background-size: cover;
}



.content {
      width: 94%;
      margin: 4em auto;
      font-size: 20px;
      line-height: 30px;
      text-align: justify;
}


.name{
      line-height: 60px;
      position: fixed;
      float: left;
      margin: 16px 46px;
      color: black;
      font-size: 20px;
      letter-spacing: 2px;
      font-family: 'Montserrat', sans-serif;
}

.name2{
    line-height: 60px;
      position: fixed;
      
      float: left;
      margin: 16px 46px;
      color: white;
      font-size: 20px;
      letter-spacing: 2px;
      font-family: 'Montserrat', sans-serif;

}

.smenu{
    text-decoration: none;
      font-size: 16px;
    color: white;
}

.submenu2{
     text-decoration: none;
      font-size: 16px;
    color: black;
}




nav {
          position: fixed;
          width: 100%;
          line-height: 60px;
    }



nav ul {
      line-height: 60px;
      list-style: none;
      background: rgba(0, 0, 0, 0);
      overflow: hidden;
      padding: 0;
      text-align: right;
      margin: 0;
      padding-right: 40px;
      transition: 1s;
      text-decoration: none;

}

nav.black ul {
      background: #000;
    text-decoration: none;

}

nav ul li {
      display: inline-block;
      padding: 16px 40px;;
    text-decoration: none;

}




      .menu-icon {
              line-height: 60px;
              width: 100%;
              background: #000;
              text-align: right;
              box-sizing: border-box;
              padding: 15px 24px;
              cursor: pointer;
              color: white;
              display: none;
        }



 @media(max-width: 786px) {

          .logo {
                position: fixed;
                top: 0;
                margin-top: 16px;
          }

          nav ul {
                max-height: 0px;
                background: #000;
              text-decoration: none;
          }

          nav.black ul {
                background: #000;
              text-decoration: none;
          }

          .showing {
                max-height: 34em;
          }

          nav ul li {
                box-sizing: border-box;
                width: 100%;
                padding: 24px;
                text-align: center;
              text-decoration: none;
          }

          .menu-icon {
                display: block;
          }
         
    }
<!DOCTYPE html>
<html lang="en">
<head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>Roberto Salas</title>
      <link rel="stylesheet" href="style.css">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
      <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
      <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300&display=swap" rel="stylesheet"> 
</head>
<body>
      <div class="wrapper">
            <header>

                  <nav>

                        <div class="menu-icon">
                              <i class="fa fa-bars fa-2x"></i>
                        </div>

                        <div  id="Title" class="name color">
                             Roberto Salas
                        </div>

                        <div class="Monse">
                              <ul >
                                  <li><a href="#" class="submenu2" >Home</a></li>
                                    <li><a href="#" class="submenu2" >About</a></li>
                                    <li><a href="#" class="submenu2" >Blog</a></li>
                                    <li><a href="#" class="submenu2">Contact</a></li>
                              </ul>
                        </div>
                  </nav>

            </header>

            <div class="content">
                  <p>
                        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
                  </p>
                  <p>
                        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
                  </p>
            </div>
      </div>

      <script type="text/javascript">

      // Menu-toggle button

      $(document).ready(function() {
            $(".menu-icon").on("click", function() {
                  $("nav ul").toggleClass("showing");
                  
                  $('a').css('color','white');
            });
      });

      // Scrolling Effect

      $(window).on("scroll", function() {
            if($(window).scrollTop()) {
                  $('nav').addClass('black');
                  $('#Title').addClass('name2');
                  $('a').css('color','white');
            }

            else {
                  $('nav').removeClass('black');
                  $('#Title').removeClass('name2');
                  $('a').css('color','black');
            }
      })


      </script>

</body>
</html>

You may add top: 0 on class .name. Then, set color: white in the media query.

.name{
      line-height: 60px;
      position: fixed;
      top: 0; /* Add top to align */
      float: left;
      margin: 16px 46px;
      color: black;
      font-size: 20px;
      letter-spacing: 2px;
      font-family: 'Montserrat', sans-serif;
}

@media(max-width: 786px) {
  /* Change the color to white */
  .name {
    color: white;
  }
}

Put the div with name:

<div  id="Title" class="name">
  Roberto Salas
</div>

above the <div class="menu-icon> in code.

Remember to change color of name on breakpoint as it is black as the navbar.

like:

@media(max-width: 786px) {
  .name {
    color: pink;
  }
}

https://jsfiddle.net/e98fxyzg/3/

Related