Bootstrap Nav Collapse(导航)滚动 - 需要隐藏溢出

时间:2015-12-19 14:26:32

标签: javascript jquery html css twitter-bootstrap

我正在继续开发我的网站,现在又遇到了另一个问题。

当导航栏在较小的屏幕上折叠时,似乎有一个滚动条表示元素溢出。

我尝试使用overflow:hidden属性在CSS中删除此问题,但它似乎无法正常工作。

请参阅下面的屏幕截图和代码段以查看问题。

@font-face {
    font-family: 'montserratlight';
    src: url('montserrat-light-webfont.eot');
    src: url('montserrat-light-webfont.eot?#iefix') format('embedded-opentype'), url('montserrat-light-webfont.woff2') format('woff2'), url('montserrat-light-webfont.woff') format('woff'), url('montserrat-light-webfont.ttf') format('truetype'), url('montserrat-light-webfont.svg#montserratlight') format('svg');
    font-weight: normal;
    font-style: normal;
}
@font-face {
    font-family: 'montserratsemi_bold';
    src: url('montserrat-semibold-webfont.eot');
    src: url('montserrat-semibold-webfont.eot?#iefix') format('embedded-opentype'), url('montserrat-semibold-webfont.woff2') format('woff2'), url('montserrat-semibold-webfont.woff') format('woff'), url('montserrat-semibold-webfont.ttf') format('truetype'), url('montserrat-semibold-webfont.svg#montserratsemi_bold') format('svg');
    font-weight: normal;
    font-style: normal;
}
#header {
    padding: 10px 0 0 0;
}
@media (min-width: 768px) {
    .navbar .navbar-nav {
        display: inline-block;
        float: none;
        vertical-align: top;
    }
    .navbar .navbar-collapse {
        text-align: center;
    }
    .navbar-brand {
        display: none;
    }
}
.navbar {
    margin-bottom: 0px;
    font-family: "montserratlight";
    text-transform: uppercase;
    border-top: 2px solid #000;
    border-bottom: 2px solid #000;
    border-radius: 0px;
}
img.logoEmpreus {
    margin-left: auto;
    margin-right: auto;
    display: block;
    margin-bottom: 10px;
}
img.logoEmpreus:hover {
    -webkit-animation-name: rubberBand;
    animation-name: rubberBand;
}
#page {
    margin: 0px auto;
}
li {
    display: inline;
    margin: 0 -1px;
}
li a {
    color: black;
    font-size: 16px;
    text-decoration: none;
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    -ms-transition: all 0.5s ease;
    transition: all 0.5s ease;
}
li a:hover {
    color: blue;
    font-size: 18px;
    text-decoration: none
}
li.active a {
    font-weight: bold;
    color: #333;
    text-decoration: none
}
ul {
    margin: 0 auto;
    font-family: "montserratlight";
    text-transform: uppercase;
}
.active {
    font-family: 'montserratsemi_bold';
}
.imageInside {
    position: relative;
    width: 100%;
    /* for IE 6 */
}
h2 {
    margin-top: 0px;
    margin-bottom: 0px;
}
h2 span {
    color: white;
    font: bold 0.8em 'montserratsemi_bold', Helvetica, Sans-Serif;
    letter-spacing: -1px;
    background: rgb(0, 0, 0);
    /* fallback color */
    
    background: rgba(0, 0, 0, 0.7);
    padding: 10px;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}
#base ul {
    margin: 0 auto;
    border-top: 2px solid #000;
    border-bottom: 2px solid #000;
    padding: 10px;
    text-align: center;
    font-family: "montserratlight";
    text-transform: uppercase;
}
<!DOCTYPE html>
<head>
   <title>Problems | Stack Overflow</title>
   <!-- Tab Title -->
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body>
   <div id = "header">
      <!-- Empreus logo Image. Animated. Width 300px. -->
      <img class = "logoEmpreus animated" src = "http://bit.ly/1P2ZlbH" alt="Empreus" width="300" />
   </div>
   <div class="container">
      <nav class="navbar navbar-default" role="navigation">
         <!-- Brand and toggle get grouped for better mobile display -->
         <div class="navbar-header">
            <a class="navbar-brand" href="#">Stack Overflow</a>
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
            <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 navbar-ex1-collapse">
            <ul class="nav navbar-nav">
               <li><a href="#">Option 1</a></li>
               <li><a href="#">Option 2</a></li>
               <li><a href="#">Option 3</a></li>
               <li><a href="#">Option 4</a></li>
               <li><a href="#" class="active"><b>The Problem</b></a></li>
            </ul>
         </div>
         <!-- /.navbar-collapse -->
      </nav>
      <div class = "row">
         <!-- Declaration of First Row -->
         <div class="imageHolder col-md-12" style="margin-top:10px;">
            <!-- Image Container as DIV -->
            <div class = "imageInside hvr-underline-from-center" >
               <h2><span>Logo Issue.</span></h2>
               <img id = "imageHomeJPG" src="http://bit.ly/1P2Ylo3" style="width:100%" />
            </div>
            <!-- Image Link -->
         </div>
      </div>
      <div class="row">
         <div id = "base" class="col-md-12" style="margin-bottom:10px">
            <p>
            <ul class="col-md-12">
               <!-- MAIN NENU BAR -->
               <li><a href="#">Copyright Whatever</a></li>
            </ul>
            <!-- Unordered lists.-->
            </p>
         </div>
         <!-- Navigation HTML Markup -->
      </div>
   </div>
</body>
</html>

Image showing the overflow scroll bar

如何删除此滚动条?

2 个答案:

答案 0 :(得分:2)

事实上,这个问题似乎更容易回答。
在Bootstrap中,overflow - x文件中默认启用了bootstrap.css属性。

.navbar-collapse {
padding-right: 15px;
padding-left: 15px;
overflow-x: visible;
-webkit-overflow-scrolling: touch;
border-top: 1px solid transparent;
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1);
}

要解决此问题,需要进行简单的属性更改。 Overflow-x:hidden

所以在折叠的导航栏上不再滚动!

答案 1 :(得分:1)

此CSS规则导致您的溢出。

li {
  display:inline;
  margin:0 -1px;
}

删除它,只需使用特定选择器定位元素即可。现在,您的菜单将在移动设备和您的悬停属性上保持对齐,以显示蓝色。

请参阅工作示例摘录。

#header {
  padding: 10px 0 0 0;
}
#header .logoEmpreus {
  margin-left: auto;
  margin-right: auto;
  display: block;
  margin-bottom: 10px;
}
#header .logoEmpreus:hover {
  -webkit-animation-name: rubberBand;
  animation-name: rubberBand;
}
@media (min-width: 768px) {
  .navbar.navbar-default .navbar-nav {
    display: inline-block;
    float: none;
    vertical-align: top;
  }
  .navbar.navbar-default .navbar-collapse {
    text-align: center;
  }
  .navbar.navbar-default .navbar-brand {
    display: none;
  }
}
.navbar.navbar-default {
  margin-bottom: 0px;
  font-family: "montserratlight";
  text-transform: uppercase;
  border-top: 2px solid #000;
  border-bottom: 2px solid #000;
  border-radius: 0px;
}
.navbar.navbar-default .navbar-nav ul {
  margin: 0 auto;
  font-family: "montserratlight";
  text-transform: uppercase;
}
.navbar.navbar-default .navbar-nav li a {
  color: black;
  font-size: 16px;
  text-decoration: none;
  -webkit-transition: all 0.5s ease;
  -moz-transition: all 0.5s ease;
  -o-transition: all 0.5s ease;
  -ms-transition: all 0.5s ease;
  transition: all 0.5s ease;
}
.navbar.navbar-default .navbar-nav li a:hover {
  color: blue;
  font-size: 18px;
  text-decoration: none
}
.navbar.navbar-default .navbar-nav .active {
  font-family: 'montserratsemi_bold';
}
.navbar.navbar-default .navbar-nav li.active a {
  font-weight: bold;
  color: #333;
  text-decoration: none
}
<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.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div id="header">
  <!-- Empreus logo Image. Animated. Width 300px. -->
  <img class="logoEmpreus animated" src="http://bit.ly/1P2ZlbH" alt="Empreus" width="300" />
</div>

<div class="container">

  <nav class="navbar navbar-default" role="navigation">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <a class="navbar-brand" href="#">Stack Overflow</a>
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
        <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 navbar-ex1-collapse">
      <ul class="nav navbar-nav">
        <li><a href="#">Option 1</a>
        </li>
        <li><a href="#">Option 2</a>
        </li>
        <li><a href="#">Option 3</a>
        </li>
        <li><a href="#">Option 4</a>
        </li>
        <li><a href="#" class="active"><b>The Problem</b></a>
        </li>
      </ul>
    </div>
    <!-- /.navbar-collapse -->
  </nav>

</div>