wolfgang1983 wolfgang1983 - 3 months ago 18
CSS Question

Custom css on bootstrap navbar not displaying correct

On my bootstrap navbar when the navbar is in desktop mode it should show my border-top css

But for some reason it shows my border-left css It should only show border-left when mobile 768px and under.

Question: How can I make sure when the navbar is shows the correct border for when it is in mobile or desktop

Codepen Example



body {
background: #222;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin: 0;
}
hr {
border-top: 10px solid #444444;
position: fixed;
}
.page-wrapper {
margin-top: 40px;
}
.custom-nav {
margin-bottom: 0;
background: #333333;
border: none;
border-radius: 0;
}
.custom-nav .navbar-brand {
color: #FFFFFF;
}
.custom-nav .navbar-brand:hover {
color: #FFFFFF;
}
.custom-nav .navbar-nav > .active > a,
.custom-nav .navbar-nav > .active > a:hover,
.custom-nav .navbar-nav > .active > a:focus {
background: none;
color: #ffffff;
}
.custom-nav .navbar-nav > li > a {
color: #ffffff;
font-size: 14.5px;
text-align: center;
}
.custom-nav .navbar-nav > li > a.home {
border-top: 2px solid #AC3931;
}
.custom-nav .navbar-nav > li > a.home:hover,
.custom-nav .navbar-nav > li > a.home:focus {
background-color: #AC3931;
}
.custom-nav .navbar-nav > li > a.forum {
border-top: 2px solid #F6AE2D;
}
.custom-nav .navbar-nav > li > a.forum:hover,
.custom-nav .navbar-nav > li > a.forum:focus {
background-color: #F6AE2D;
}
.custom-nav .navbar-nav > li > a.blog {
border-top: 2px solid #3B910D;
}
.custom-nav .navbar-nav > li > a.blog:hover,
.custom-nav .navbar-nav > li > a.blog:focus {
background-color: #3B910D;
}
.custom-nav .navbar-nav > li > a.examples {
border-top: 2px solid #2868B7;
}
.custom-nav .navbar-nav > li > a.examples:hover,
.custom-nav .navbar-nav > li > a.examples:focus {
background-color: #2868B7;
}
.custom-nav .navbar-collapse .navbar-nav > li > a.home {
border-top: none;
border-left: 2px solid #AC3931;
}
.custom-nav .navbar-collapse .navbar-nav > li > a.forum {
border-top: none;
border-left: 2px solid #F6AE2D;
}
.custom-nav .navbar-collapse .navbar-nav > li > a.blog {
border-top: none;
border-left: 2px solid #3B910D;
}
.custom-nav .navbar-collapse .navbar-nav > li > a.examples {
border-top: none;
border-left: 2px solid #2868B7;
}
.page {
background: #EEEEEE;
/*box-shadow: 6px 6px 0px #989898, 12px 12px 0px #6B6666;*/
min-height: 500px;
padding: 20px;
}
.module {
background: #fff;
padding: 20px;
margin-bottom: 40px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
.module .module-info {
color: #999;
font-size: 0.8em;
letter-spacing: 0.2em;
text-transform: uppercase;
font-family: 'source code pro';
}
.module .module-title {
font-size: 2.2em;
color: #000;
font-weight: bold;
display: block;
margin-bottom: 10px;
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="page-wrapper">

<div class="container">

<nav class="navbar navbar-inverse custom-nav">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li ><a class="home" href="#">Home</a></li>
<li><a class="forum" href="#">Forum</a></li>
<li><a class="blog" href="#">Blog</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle examples" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">CodeIgniter Examples <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 -->

</nav>
</div><!-- /.container-->

</div>

<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>




Answer

You can use CSS @media rule and then put all related CSS code for particular mobile with screen size inside it, like below:

.custom-nav .navbar-nav > li > a.examples {
	border-top: 2px solid #2868B7;
}

.custom-nav .navbar-nav > li > a.examples:hover, 
.custom-nav .navbar-nav > li > a.examples:focus {
    background-color: #2868B7;
}

@media only screen and (max-width: 768px) {
    
  .custom-nav .navbar-collapse .navbar-nav > li > a.home {
      border-top: none;
	  border-left: 2px solid #AC3931;
  }

  .custom-nav .navbar-collapse .navbar-nav > li > a.forum {
	  border-top: none;
	  border-left: 2px solid #F6AE2D;
   }

  .custom-nav .navbar-collapse .navbar-nav > li > a.blog {
	  border-top: none;
	  border-left: 2px solid #3B910D;
  }

  .custom-nav .navbar-collapse .navbar-nav > li > a.examples {
	  border-top: none;
	  border-left: 2px solid #2868B7;
  }
}

For more detail check here.. Hope it helps.

Comments