Bootstrap - 折叠的菜单项水平而不是垂直显示

时间:2017-01-10 03:41:21

标签: javascript jquery html css twitter-bootstrap

出于某种原因,无论我做什么,我的导航栏都会在折叠时水平显示菜单项,并在其中间显示我的徽标!当我使用visible-xs等时,由于某种原因它可以在左边对齐!

我尝试过在其他类似的溢出问题上找到的方法,例如显示列表项inline-block(尽管不想使用内联样式!)

但没有什么对我有用!

我知道问题是因为我的桌面视图中的菜单项中心有我的徽标,因此它不是标准菜单,但必须有一种方法可以使我的菜单项垂直显示而不显示徽标在中间?我是新手,所以也许我只是愚蠢而且缺少一些东西?

我正在使用jquery mobile如果它有任何区别(这可能是打破菜单并阻止它被关闭吗?)

这是我所拥有并尝试过的:

导航栏的HTML:

<!DOCTYPE html>
<html lang="en">

<head>

  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge, no-index">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- The above 3 meta tags must come first in the head; any other head content must come after these tags -->
  <meta name="description" content="">
  <meta name="author" content="">
  <link rel="icon" href="favv.ico">


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js">
  </script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>

  <script type="text/javascript" src="../node_modules/bootstrap/dist/js/bootstrap.js"></script>

  <script src="../assets/js/main.js"></script>



  <!-- Custom styles for this template -->
  <link href="../node_modules/jquery-mobile/mobilestyles.css" rel="stylesheet">
  <link href="/Silver-Lining/css/template.css" rel="stylesheet">



  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
  <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet">


  <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>


  <![endif]>






  <!--============ Navigation ===============-->



  <nav class="navbar navbar-default navbar-fixed-top text-center">


    <nav id="navbar-primary" class="navbar" role="navigation">
      <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
          <div class="top-social">
            <a href="tel:+1-303-499-7111"> <i class="fa fa-phone" aria-hidden="true">   
     </i> 0787000000
            </a>

            <a href="#">
              <i class="fa fa-facebook-official" aria-hidden="true"></i>
            </a>
            <a href="#">
              <i class="fa fa-twitter-square" aria-hidden="true"></i>
            </a>

            <a href="#">
              <i class="fa fa-instagram" aria-hidden="true"></i>
            </a>

            <a href="#">
              <i class="fa fa-linkedin-square" aria-hidden="true"></i>
            </a>

          </div>
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-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>
        <div class="collapse navbar-collapse" id="navbar-primary-collapse">
          <ul class="nav navbar-nav">
            <li><a href="about-us.php" data-ajax="false">ABOUT</a></li>
            <li><a href="gallery.php" data-ajax="false">OUR CARS</a></li>
            <li><a href="Prices.php" data-ajax="false">PRICES</a></li>
            <a class="hidden-sm-down" href="index.php" data-ajax="false"><img src="../assets/images/logo" width="250" alt="Logo"></a>
            <li><a href="#" data-ajax="false">PACKAGES</a></li>
            <li><a href="gallery.php" data-ajax="false">BLOG</a></li>
            <li><a href="contact.php" data-ajax="false">CONTACT</a></li>

          </ul>
        </div>
        <!-- /.navbar-collapse -->

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

使示例菜单项在Collapse:

上垂直显示的CSS示例
 @media (max-width: 932px) {
   #navbar-primary .navbar-nav li a {
     float: none;
     position: inherit;
     display: inline-block !important;
     vertical-align: top;
     max-height: 300px;
   }
 }

导航栏的Css

// Remove excess borders
.navbar-default {
  border-top: none;
  border-left: 0;
  border-right: none;
  margin-top: 0px;
  padding-bottom: 10px;
  font-family: 'Open Sans Condensed', sans-serif;
  margin-bottom: 0;
  font-size: 18px;
  border-color: transparent;
  white-space: normal;
}

.navbar-default .navbar-nav > li {
  margin-top: 20px;
}

任何帮助都会非常感激,我已经非常困惑并至少坚持了几天,并且真的想要保持相同的导航栏而不必再重复一遍

1 个答案:

答案 0 :(得分:0)

在玩了很多代码之后我发现了

@media screen and (max-width: 768px) {
#navbar-primary .navbar-nav > li {
display: block;
}
}

给了我想要的结果(折叠时垂直堆叠的菜单项!)