0

Is it possible to use the same procedure that Bootstrap use when dim the page when modal opens?

I would like it to dim the page when i hover the bootstrap navbar.
Of corse i do not want the navbar to be dimed!

How does the modal-dim work?
Can i use the same css?

Björn C
  • 3,860
  • 10
  • 46
  • 85
  • you should be able to add a div with 100% width and height position fixed z-index where only your nav has higher z-index and little transparent background to achieve the same effect – john Smith May 29 '18 at 19:57
  • You can try google first http://jesseshowalter.com/articles/css-dark-overlays/ – Surreal May 29 '18 at 19:58
  • Well.. i know there are a lot of ways doing this. But my question asks if i can use the already existing Bootstrap modal effect?! – Björn C May 29 '18 at 20:01

2 Answers2

1

No, you cannot use the existing Bootstrap modal effect because that would dim everything on the page including the navbar.

Boric
  • 822
  • 7
  • 26
  • You should delete your answer because it is not true. You can use `rgba` – mahan May 30 '18 at 10:28
  • Adding CSS that sets rgba color is adding a new effect, not using the existing Bootstrap modal effect as the question asked. – Boric May 30 '18 at 18:42
1

You can do so with pure CSS supported by all major browsers.

.navbar:hover+.nav-sibling {
  display: block;
  opacity: 0.5;
  background: rgba(0, 0, 0, 1);
  transition: opacity .15s linear;
}

.nav-sibling {
  position: fixed;
  display: none;
  overflow: hidden;
  outline: 0;
  /* equal to the navbar height */
  top: 56px;
  bottom: 0;
  left: 0;
  right: 0;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              Dropdown
            </a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>
<div class="nav-sibling">

</div>
<footer class=" container-fluid bg-dark text-white py-5">
  <div class="row">
    <div class="col-12">
      <h6>Lorem ipsum</h6>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget sapien dolor. Nam aliquam augue ante, et sodales felis vulputate iaculis.</p>
    </div>
  </div>
</footer>

nav-sibling is the same as bootstrap modal code except the top property.


Update

Opacity sets the opacity value for an element and all of its children; While RGBA sets the opacity value only for a single declaration. - StackOverflow - opacity vs RGBA

It is better that you use a number between 0 and 1 for the alpha channel instead of the opacity. In the code below, I have used 0.9.

.navbar:hover+.nav-sibling {
  display: block;
  background-color: rgba(0, 0, 0, 0.9);
  transition: all .15s linear;
}
mahan
  • 12,366
  • 5
  • 48
  • 83