musicformellons
musicformellons

Reputation: 13383

Bootstrap NavBar opacity for small and large screen

I want my Navbar topbar to have opacity 0.75, but the Navbar dropdown menu (appears at small screen) to have opacity 1.0; My current code works great (using rgba colornotation to circumvent the inheritance problems between parent -Toolbar- en children -Dropdownmenu- when setting opacities as separate values) on small screens [yellow is 'not opaque'; purple is 'opaque']:

small_screen

But at large screens I now get: enter image description here

Just left and right corners are not opaque, mainpart of topbar is opaque; Whereas I would like the entire topbar to be not opaque (and the same color obviously).

I understand when the dropdown menu is collapsed into the topbar it takes its opacity features with it, but that's not what I want.

Here is a fiddle which shows the behaviour when changing the screen width: http://jsfiddle.net/musicformellons/no2wfz9m/4/

This css part sets the opacity for the 'dropdown menu' (but apparently for all menus...):

.navbar-default .navbar-collapse, .navbar-default .navbar-form {
    border-color: rgb(222, 145, 139);
    background-color: rgba(155,155,255,1);
}

Upvotes: 0

Views: 936

Answers (1)

vanburen
vanburen

Reputation: 21663

Just put the .navbar.navbar-custom .navbar-collapse inside a media query.

*I added a custom class (navbar-custom) so the CSS Core isn't directly over written.

.navbar.navbar-custom {
  margin-bottom: 19px;
  background-color: rgba(224, 178, 63, 0.75);
  border-color: rgba(192, 40, 8, 0.75)
}
/*brandname*/

.navbar.navbar-custom .navbar-brand {
  color: rgba(255, 217, 217, 1);
  padding: 14x15px;
  font-size: 28px;
}
/*Other menu font items*/

.navbar.navbar-custom .navbar-nav > li > a {
  color: rgba(241, 210, 210, 1);
  font-size: 20px;
}
.navbar.navbar-custom .navbar-brand:hover {
  color: rgba(255, 255, 255, 1);
}
.navbar.navbar-custom .navbar-nav>li>a:hover {
  color: rgba(255, 255, 255, 1);
}
.navbar.navbar-custom .navbar-toggle {
  border-color: transparent;
}
@media (max-width: 767px) {
  .navbar.navbar-custom .navbar-collapse,
  .navbar.navbar-custom .navbar-form {
    border-color: rgb(222, 145, 139);
    background-color: rgba(155, 155, 255, 1);
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<!-- Static navbar -->
<nav class="navbar navbar-default navbar-custom navbar-static-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span>

        <div id="nav-icon4"> <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>

        </div>
      </button> <a class="navbar-brand" href="{% url 'home' %}">Brandname</a>

    </div>
    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li><a href="{% url 'home' %}">Home</a>

        </li>
        <li><a href="{% url 'about' %}">About</a>

        </li>
        <li><a href="{% url 'contact' %}">Contact</a>

        </li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">Link</a>

        </li>
        <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>

          <ul class="dropdown-menu">
            <li><a href="#">Action</a>

            </li>
            <li><a href="#">Another action</a>

            </li>
            <li><a href="#">Something else here</a>

            </li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a>

            </li>
          </ul>
        </li>
      </ul>
    </div>
    <!-- /.navbar-collapse -->
  </div>
  <!-- /.container-fluid -->
</nav>

Upvotes: 2

Related Questions