1

I have a nav bar with height: 5vh and the rest of the page inside a container with height: 95vh. I use display: flex for my nav bar <ul> element and align-items: stretch so that the <li> elements have 100% height of the nav bar. Also I set the height of the <a> elements to 100% of the parent <li> elements.

However, the problem is that I want the text of the <a> elements to be vertically aligned to center (not top). I can't set a vertical padding for the <a> elements because this will affect the height of the element and will not make its height responsive.

Here is the full code:

<!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>
    <style>

        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
        }

        nav ul {
            background-color: aquamarine;
            list-style-type: none;
            margin: 0;
            padding: 0;
            height: 5vh;
            display: flex;
            align-items: stretch;
        }

        nav a {
            display: inline-block;
            padding: 0 10px;
            height: 100%;
            text-decoration: none;
            font-weight: bold;
            color: navy;
        }

        nav a:hover {
            background-color: rgb(95, 206, 169);
        }

        nav a.active {
            background-color: azure;
        }

        .content {
            height: 95vh;
            overflow: hidden;
            background-color: silver;
        }
    </style>
</head>

<body>

    <!-- Nav bar -->
    <nav>
        <ul>
            <li><a class="active" href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact Us</a></li>
        </ul>
    </nav>

    <!-- Rest of the page -->
    <div class="content"></div>

</body>

</html>