自举导航栏上的自定义css显示不正确

时间:2016-08-09 12:32:35

标签: css twitter-bootstrap

在我的引导程序导航栏上,当导航栏处于桌面模式时,它应显示我的border-top css

但由于某种原因,它显示我的边框左侧css它应该只显示移动768px及以下的边框左侧。

问题:如何确保导航栏在移动设备或桌面设备上显示正确的边框时

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>

3 个答案:

答案 0 :(得分:2)

您可以使用CSS @media rule,然后将特定手机的所有相关CSS代码放入其中,如下所示:

.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;
  }
}

有关详情,请查看here ..希望有所帮助。

答案 1 :(得分:1)

您应该在最大宽度:768px的媒体查询中添加border-left css。

@media (max-width:768px){
/*put your css here*/
}

仅在768px及以下的屏幕宽度上显示您的css。

答案 2 :(得分:0)

您可以使用媒体查询设置不同的断点并更改每个断点的样式。如下所示:

/* Desktops and laptops ----------- */
@media only screen  and (min-width : 1224px) {
/* Styles */
}