Vertical Navbar, center text vertically?

I have coded a vertical navbar and I want to center the lists vertically, but somehow it doesn’t work and I don’t want to use the line-height property, because it changes the margin too. I’d really appreciate some help. Here’s the code:

   * {
            padding: 0px;
            margin: 0px;
        }

        .navbar {
            position: absolute;
            height: 100%;
            width: 10%;
            background-color: aquamarine;
            transition: 0.5s ease-in;
        }

        .navbar:hover {
            width: 90%;
        }

        .navbar:hover li{
           width: 100%;
           opacity: 1;
       }

        li {
            text-align: center;
            transition: 0.5s ease-in;
            opacity: 0;
            margin: 10px;
            vertical-align: middle;
        }

        a {
            text-decoration: none;
            color: black;
            font-size: 20px;
        }
  <div class="navbar">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Services</a></li>
            <li><a href="#">Feedback</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </div>

enter image description here

20 thoughts on “Vertical Navbar, center text vertically?”

  1. You could display the <ul> (unordered list) as a grid. You never designated style overrides for the <ul> element that exists within your .navbar container.

    * {
      padding: 0px;
      margin: 0px;
    }
    
    .navbar {
      display: flex; /* Allow inner grid to size itself */
      justify-content: center; /* Horizontal alignment */
      align-items: center; /* Vertical alignment */
      position: absolute;
      top: 0; /* Make sure it is flush to the top */
      left: 0; /* Make sure it is flush to the left */
      height: 100%;
      width: 10%;
      background-color: aquamarine;
      transition: 0.5s ease-in;
    }
    
    .navbar:hover {
      width: 90%;
    }
    
    .navbar:hover li {
      opacity: 1;
    }
    
    .navbar > ul {
      list-style-type: none; /* Disable default list bullets */
      display: grid; /* Display the items in a grid format */
      grid-auto-flow: row; /* Display children as rows */
      grid-row-gap: 0.5em; /* Spacing between rows */
    }
    
    .navbar > ul li {
      margin: 0; /* Remove default margin */
      padding: 0; /* Remove default padding */
      text-align: left; /* Align text to the left */
      transition: 0.5s ease-in;
      opacity: 0;
    }
    
    a {
      text-decoration: none;
      color: black;
      font-size: 20px;
    }
    
    a:hover {
      text-decoration: underline; /* Change up the presentation a bit... */
    }
    <div class="navbar">
      <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Services</a></li>
        <li><a href="#">Feedback</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </div>
    Reply
  2. community action agency allegan community bank branch locations , positive affirmations sleep. positive pregnancy test nothing on ultrasound lyrica dose generic lyrica , friends apparel community national bank community action agency warner robins ga , community aid pa community health center middletown ct covid testing? community action agency rockford il positive quotes hard times, positive adjectives to describe a person positive feedback system.
    friends how many of us have them , community action near me community action agency in gulfport mississippi positive quotes mental health.

    Reply
  3. software engineer 2020 drawing program website to buy Autocad software office software assurance benefits. solidworks software 2020 download latest office software for mac engeeeneringu#$sssaunnplus , gx6605s new software 2020 download. win10-radeon-software-adrenalin-2020-edition-20.1.2-jan15, mastercam 2020 software free download software office 2003 free download with key macbook office suite. software new grad 2020 ca office software free download, new software 2020 free download.

    Reply
  4. get a loan online now ireland i need loan to pay off debt [url=https://ineedloan.me/#]i need a loan[/url] quick loans zimbabwe. quick loans athens tennessee how to get a loan today online, personal loans bad credit near me. online loans payday advance [url=https://suggarporn.com/forced-anal-tied-face-down/#comment-12273]unsecured loan default uk urgent[/url] d4_d46f find me a loan for bad credit, how to get a guaranteed loan with bad credit, unsecured loans are those. does bank of america have unsecured personal loans quick loans lenoir city tn, unsecured loans for bad credit not payday loans quicken loans arena. why you need financial assistance find me a loan shark, best unsecured loan rates in jamaica how to get a fha loan with bad credit. where can i get a small loan with bad credit near me unsecured personal loans indianapolis.

    Reply

Leave a Comment