简体   繁体   中英

Bootstrap - Collapsed menu items appearing horizontally instead of vertically

For some reason no matter what I do my navbar displays menu items horizontally on collapse with my logo in the middle of them! When I used the visible-xs etc it aligns it to the left for some reason when it is visible!

I have tried methods found on other similar overflow questions such as displaying the list items inline-block (despite not wanting to use inline-styles!)

But nothing is working for me!

I know the problem is because I have my logo in the center of my menu items on desktop view, so it isn't a standard menu but there must be a way around this to make my menu items display vertically without the logo in the middle? I am new-ish to this so perhaps I am just being stupid and missing something?

I am using jquery mobile if it makes any difference (could it be this breaking the menu and preventing it from being closed?)

here is what I have and have tried:

HTML for navbar:

<!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 -->

CSS example to make menu items appear vertically on Collapse:

 @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 for navbar

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

Any help would be much appreciated, I have been very confused and stuck on this for several days at least and really want to keep the same navbar without having to make it all over again

After much playing with the code I found that

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

gave me the result I wanted (vertically stacked menu items on collapse!)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM