Search code examples
htmlcssnavbarbootstrap-5transparent

I can't get my Bootstrap 5 Navbar to appear transparent?


My bootstrap Navbar is white and despite trying everything i can find on Stack i cant override the white to make it transparent.

I have tried setting the background to transparent The image behind is set to VH100 so should be behind the nav I have tried using Inspect and targeting every colour instruction i could find I removed the bg class from the navbar thinking that would help

Here is my html

<nav class="navbar navbar-expand-sm navbar-light">
            <div class="container-fluid">
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
                  <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarTogglerDemo01">
            <a href="index.html" class="navbar-brand"><img src="/assets/images/MothersSpinesLogo.png" alt="Mothers Spines MS Logo"></a>
            <ul id="nav" class="navbar-nav ms-auto">
                <li class="active nav-item">
                    <a class="nav-link"href="index.html">HOME</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="about.html">ABOUT</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="contact.html">CONTACT</a>
                </li>
            </ul>
        </nav>

and my CSS;

/* Navigation */
.navbar-brand {
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    max-height: 60px;
    max-width: 60px;
    margin-left: 30px;
}

.navbar {
    align-items: end;
    background: none;
    background-color: rgba(0, 0, 0, 0.0);
    --bs-navbar-nav-link-padding-x: 3.5rem;
    font-family: 'Montserrat';
    font-size: 120%;
    list-style-type: none;
    letter-spacing: 1px;
    --bs-navbar-toggler-border-color: rgba(0, 0, 0, 0.0);
}


.navbar a {
    text-decoration: none;
    color: #252525;
}

.nav-item {
    padding-top: 25px;
}

Screenshot of Nav and Inspect open


Solution

    1. .navbar { background-color: transparent; }
    2. Add the following to the image: height: 100vh;, position: absolute; and top: 0;.

    If you just set height: 100vh; to the image, the image will be full viewport height, but it will start AFTER the navbar. You want to place it below the navbar. You do this by setting position: absolute; and top: 0;.

    In short, the problem is caused by the image.