javascripthtmlcssportfolio

My portfolio issue: element upon mouse hover shifts everything to the right


I am trying to create a effect when you hover over my abbrivated name it expands to its full size however,I've run into a problem that detracts from the visual appeal of the website I'm trying to achieve and makes it appear tacky.What I want is for the element to expand in a isolated manner and does not affect anything else on the website.

Here is the link:https://jsfiddle.net/dkpsgo73/

    <nav>
      <header>
        <h1 class="Name">
          [
          <span id="zk-trigger"><span class="Fname"> S</span><span id="hide1" class="hide"><span    class="Fname">eid</span></span>
            J<span id="hide2" class="hide">ama</span>
          </span>
          ]
        </h1>
      </header>
      <!-- Navigational Bar -->
      <div class="nav-menu">
        <ul>
          <li><a href="#Home">Home</a></li>
          <li><a href="#About">About</a></li>
          <li><a href="#Projects">Projects</a></li>
          <li><a href="#Skills">Skills</a></li>
          <li><a href="#Contact">Contact</a></li>
        </ul>
      </div>
      <!-- Navigational Bar -->
    </nav>

I read a lot of different advise on the subject, including position absolute and z-index, but I was unable to find a solution because I am still very new to learning how to code.


Solution

  • Add the following CSS:

    header {
      min-width: 200px;
    }
    

    See the snippet below.

    html,
    body {
      margin: 0;
      font-family: "Rubik", sans-serif;
      background-color: #333333ff;
    }
    
    /* Font Config */
    h1 {
      font-weight: normal;
      font-size: 25px;
      text-transform: uppercase;
      letter-spacing: 1px;
      margin: 0 0 0 0;
      color: #f6f2f0;
    }
    
    /* Navigation Bar */
    nav {
      /*Keeps the nav fixed*/
      position: fixed;
      /*Size of the nav bar*/
      height: 70px;
      width: 100%;
      /*Spaces out the nav elements*/
      display: flex;
      justify-content: space-around;
      align-items: center;
      padding: 0 10px;
      /*Blur property*/
      backdrop-filter: blur(5px);
      background-color: #262626ff;
      opacity: 0.9;
      border-bottom: 5px solid #6527a7ff;
    }
    
    /* Navigation Bar */
    .Name {
      display: inline;
      font-style: italic;
    }
    
    #hide1,
    #hide2 {
      display: inline-block;
      max-width: 0;
      opacity: 0;
      transition: max-width 0.2s, opacity 0.2s;
    }
    
    #zk-trigger:hover #hide1,
    #zk-trigger:hover #hide2 {
      max-width: 100px;
      opacity: 1;
      transition: max-width 0.5s, opacity 0.2s;
    }
    
    .Fname {
      color: #ffc000;
    }
    
    li {
      display: inline;
      padding: 8px;
      font-size: 20px;
    }
    
    /* My Nav List Position */
    .nav-menu {
      display: flex;
      justify-content: flex-end;
    }
    
    /* My Nav List Position */
    
    /* Navigation Link Interaction */
    .nav-menu li a {
      color: #f6f2f0;
    }
    
    .nav-menu li a:link {
      text-decoration: none;
    }
    
    .nav-menu li a:hover {
      color: #ffc000;
      text-decoration: none;
    }
    
    /* Navigation Link Interaction */
    
    /* Added */
    header {
      min-width: 200px;
    }
    <!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>Portfolio</title>
      <link href="Styles.css" rel="stylesheet" />
      <link href="https://fonts.googleapis.com/css2?family=Rubik:wght@300;400&display=swap" rel="stylesheet" />
    </head>
    
    <body>
      <nav>
        <header>
          <h1 class="Name">
            [
            <span id="zk-trigger"><span class="Fname"> S</span><span id="hide1" class="hide"><span class="Fname">eid</span></span>
            J<span id="hide2" class="hide">ama</span>
            </span>
            ]
          </h1>
        </header>
        <!-- Navigational Bar -->
        <div class="nav-menu">
          <ul>
            <li><a href="#Home">Home</a></li>
            <li><a href="#About">About</a></li>
            <li><a href="#Projects">Projects</a></li>
            <li><a href="#Skills">Skills</a></li>
            <li><a href="#Contact">Contact</a></li>
          </ul>
        </div>
        <!-- Navigational Bar -->
      </nav>
    </body>
    
    </html>