Bootstrap小窗口导航栏下拉列表无法正常工作

时间:2017-06-21 08:10:21

标签: javascript html css twitter-bootstrap

我试图用bootstrap开发我的第一个网站,所以我对它很陌生。 我使用反向导航栏,我注意到当我的浏览器窗口变小时,导航栏的右侧会在一个不起作用的下拉菜单上编译。它没有下拉菜单。

窗口正常如此 Normal Window

这是在导航栏上无法正常工作的下拉菜单。 PS-它的红色边界。 This is the dropdown menu that doesn't work properly on the navbar. PS- Its red bordered.

这是我的HTML:



body { 
    margin: 0;
}
.jumbotron{
    align-items:center;
    display:flex;
    background-image:url('https://static.pexels.com/photos/392018/pexels-photo-392018.jpeg');
    background-size:cover;
    height:450px;
    color:white;
    height: 50vh;
}
* {
    box-sizing: border-box;
}
.columns {
    float: left;
    width: 33.3%;
    padding: 8px;
}
.price {
    list-style-type: none;
    border: 1px solid #eee;
    margin: 0;
    padding: 0;
    -webkit-transition: 0.3s;
    transition: 0.3s;
}
.price:hover {
    box-shadow: 0 8px 12px 0 rgba(0,0,0,0.2)
}
.price .header {
    background-color: #2D2727;
    color: white;
    font-size: 25px;
}
.price li {
    border-bottom: 1px solid #eee;
    padding: 20px;
    text-align: center;
}
.price .grey {
    background-color: #eee;
    font-size: 20px;
}
.button {
    background-color: #4CAF50;
    border: none;
    color: white;
    padding: 10px 25px;
    text-align: center;
    text-decoration: none;
    font-size: 18px;
}
@media only screen and (max-width: 600px) {
    .columns {
        width: 100%;
    }
}

<!DOCKTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <title>WebHosting</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
        <link rel="stylesheet" href="main.css" type="text/css">
    </head>
    <body>
        <!--NavBar-->
        <div class="row">
            <div class="col-lg-8">
                <nav class="navbar navbar-inverse navbar-fixed-top">
                    <div class="container-fluid">
                        <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>
                            <a class="navbar-brand" href="index.html">WebHosting</a>
                        </div>
                        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                            <ul class="nav navbar-nav navbar-right">
                                <li><a href="contactos.html">Contactos</a></li>
                                <li><a href="preços.html">Preços</a></li>
                            </ul>
                        </div>
                    </div>
                </nav>
            </div>
        </div><!--NavBar END-->
        <section class="jumbotron">
            <div class="container">
                <div class="row text-center">
                    <h1>WebHosting</h1>
                    <p>Host your WebSite now!!</p>
                    <p><a class="btn btn-primary btn-lg" href="precos" role="button">Learn more</a></p>
                </div>
            </div>
        </section>
        <div class="columns">
            <ul class="price">
                <li class="header">Host</li>
                <li class="grey">Free</li>
                <li>Sem criação de WebSite</li>
                <li>Sem Dominio</li>
                <li class="grey"><a class="btn btn-primary btn-lg" href="precos" role="button">Buy Now</a></li>
            </ul>
        </div>
        <div class="columns">
            <ul class="price">
                <li class="header">Host + WebSite</li>
                <li class="grey">€ 9.99</li>
                <li>Criação do WebSite</li>
                <li>Sem Dominio</li>
                <li class="grey"><a class="btn btn-primary btn-lg" href="precos" role="button">Buy Now</a></li>
            </ul>
        </div>
        <div class="columns">
            <ul class="price">
                <li class="header">Host + WebSite + Dominio</li>
                <li class="grey">€ 9.99 / year</li>
                <li>Criação do WebSite</li>
                <li>Dominio incluido</li>
                <li class="grey"><a class="btn btn-primary btn-lg" href="precos" role="button">Buy Now</a></li>
            </ul>
        </div>
    </body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:3)

按照给定的顺序在头部使用。

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

&#13;
&#13;
body {
  margin: 0;
}

.jumbotron {
  align-items: center;
  display: flex;
  background-image: url('https://static.pexels.com/photos/392018/pexels-photo-392018.jpeg');
  background-size: cover;
  height: 450px;
  color: white;
  height: 50vh;
}

* {
  box-sizing: border-box;
}

.columns {
  float: left;
  width: 33.3%;
  padding: 8px;
}

.price {
  list-style-type: none;
  border: 1px solid #eee;
  margin: 0;
  padding: 0;
  -webkit-transition: 0.3s;
  transition: 0.3s;
}

.price:hover {
  box-shadow: 0 8px 12px 0 rgba(0, 0, 0, 0.2)
}

.price .header {
  background-color: #2D2727;
  color: white;
  font-size: 25px;
}

.price li {
  border-bottom: 1px solid #eee;
  padding: 20px;
  text-align: center;
}

.price .grey {
  background-color: #eee;
  font-size: 20px;
}

.button {
  background-color: #4CAF50;
  border: none;
  color: white;
  padding: 10px 25px;
  text-align: center;
  text-decoration: none;
  font-size: 18px;
}

@media only screen and (max-width: 600px) {
  .columns {
    width: 100%;
  }
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<div class="row">
  <div class="col-lg-8">
    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container-fluid">
        <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>
          <a class="navbar-brand" href="index.html">WebHosting</a>
        </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="contactos.html">Contactos</a></li>
            <li><a href="preços.html">Preços</a></li>
          </ul>
        </div>
      </div>
    </nav>
  </div>
</div>
<!--NavBar END-->
<section class="jumbotron">
  <div class="container">
    <div class="row text-center">
      <h1>WebHosting</h1>
      <p>Host your WebSite now!!</p>
      <p><a class="btn btn-primary btn-lg" href="precos" role="button">Learn more</a></p>
    </div>
  </div>
</section>
<div class="columns">
  <ul class="price">
    <li class="header">Host</li>
    <li class="grey">Free</li>
    <li>Sem criação de WebSite</li>
    <li>Sem Dominio</li>
    <li class="grey"><a class="btn btn-primary btn-lg" href="precos" role="button">Buy Now</a></li>
  </ul>
</div>
<div class="columns">
  <ul class="price">
    <li class="header">Host + WebSite</li>
    <li class="grey">€ 9.99</li>
    <li>Criação do WebSite</li>
    <li>Sem Dominio</li>
    <li class="grey"><a class="btn btn-primary btn-lg" href="precos" role="button">Buy Now</a></li>
  </ul>
</div>
<div class="columns">
  <ul class="price">
    <li class="header">Host + WebSite + Dominio</li>
    <li class="grey">€ 9.99 / year</li>
    <li>Criação do WebSite</li>
    <li>Dominio incluido</li>
    <li class="grey"><a class="btn btn-primary btn-lg" href="precos" role="button">Buy Now</a></li>
  </ul>
</div>
&#13;
&#13;
&#13;