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

Time:10-18

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 >
            <div >
                <button  type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
                  <span ></span>
                </button>
                <div  id="navbarTogglerDemo01">
            <a href="index.html" ><img src="/assets/images/MothersSpinesLogo.png" alt="Mothers Spines MS Logo"></a>
            <ul id="nav" >
                <li >
                    <a href="index.html">HOME</a>
                </li>
                <li >
                    <a  href="about.html">ABOUT</a>
                </li>
                <li >
                    <a  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

CodePudding user response:

  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.

CodePudding user response:

It looks like there are issues with element placement. Code provided does work for overlaying the image.

img#bg {
  position: absolute;
}


/* 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: transparent;
  --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;
}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

<img id="bg" src="https://st3.depositphotos.com/1021722/13762/i/600/depositphotos_137623752-stock-photo-art-spring-background-fresh-flower.jpg">

<nav >
  <div >
    <div  id="navbarTogglerDemo01">
      <a href="index.html" >
        <img alt="Mothers Spines MS Logo">
      </a>
      <ul id="nav" >
        <li >
          <a  href="index.html">HOME</a>
        </li>
        <li >
          <a  href="about.html">ABOUT</a>
        </li>
        <li >
          <a  href="contact.html">CONTACT</a>
        </li>
      </ul>
</nav>

  • Related