bootstrap .navbar-header 控制button隐藏/显示

bootstrap 的导航条标签做的很完美!我们用这个标签主要解决手机端和PC端适配的问题,结果复制过来不能用。。

检查:是否引入bootstrap.css  js;

再重点检查有没有下面这行代码。

<meta name="viewport" content="width=device-width, initial-scale=1">

下面是导航条源码

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- 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>
      <a class="navbar-brand" href="#">Brand</a>
    </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 class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <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>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
      <form class="navbar-form navbar-left">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <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 -->
  </div><!-- /.container-fluid -->
</nav>

viewport 指的是我们设备显示浏览器的那块区域,这个说起来比较复杂,我们就讲讲它的用法

containt里面的数值,我们姑且把他们称作属性和值,里面有6个属性和值,分别是

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">

width:  设置的宽度,为一个正整数,或字符串"width-device"

initial-scale:  设置页面的初始缩放值,为一个数字,可以带小数

minimum-scale:  允许用户的最小缩放值,为一个数字,可以带小数

maximum-scale:  允许用户的最大缩放值,为一个数字,可以带小数

height:  设置layout viewport  的高度,这个属性对我们并不重要,很少使用

user-scalable:  是否允许用户进行缩放,值为"no"或"yes", no 代表不允许,yes代表允许

补充,initial-scale=1 意思是缩放100%同样也能达到width =device-width的效果,两者都可以用;

那么如果两个都存在,设备会选择哪个来显示呢?答案是,设备会选择最大的那个值来显示

比如:width =600   initial-scale =1 的宽度是580 那么设备会选择width =600的值

 

 

 
<!DOCTYPE html> <html> <head> <title>Car Vacation - Destination</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QLeykU8jmeO+TX3qgNkP0GNIgB6Hp" crossorigin="anonymous"> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <header> <nav class="navbar navbar-expand-lg navbar-light bg-light"> <a class="navbar-brand" href="#">Car Vacation</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav"> <li class="nav-item active"> <a class="nav-link" href="#">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Destination</a> </li> <li class="nav-item"> <a class="nav-link" href="#">About Us</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Contact</a> </li> </ul> </div> </nav> </header> <main> <section class="banner"> <h1>Destination</h1> </section> <section class="cards"> <div class="container"> <div class="row"> <div class="col-md-4"> <div class="card"> <img class="card-img-top" src="https://picsum.photos/seed/picsum/300/200" alt="Card image cap"> <div class="card-body"> <h5 class="card-title">New York</h5> <p class="card-text">New York City is the most populous city in the United States. It is known for its famous landmarks such as the Statue of Liberty, Empire State Building and Central Park.</p> <a href="#" class="btn btn-primary">Learn More</a> </div> </div> </div> <div class="col-md-4"> <div class="card"> <img class="card-img-top" src="https://picsum.photos/seed/picsum/300/200" alt="Card image cap"> <div class="card-body"> <h5 class="card-title">Paris</h5> <p class="card-text">Paris, the capital of France, is known for its artistic heritage, fashion, fine dining and iconic landmarks such as the Eiffel Tower, Notre-Dame Cathedral and the Louvre Museum.</p> <a href="#" class="btn btn-primary">Learn More</a> </div> </div> </div> <div class="col-md-4"> <div class="card"> <img class="card-img-top" src="https://picsum.photos/seed/picsum/300/200" alt="Card image cap"> <div class="card-body"> <h5 class="card-title">Tokyo</h5> <p class="card-text">Tokyo, the capital of Japan, is known for its modern skyscrapers, historic temples, shopping and entertainment districts, and unique blend of traditional and contemporary culture.</p> <a href="#" class="btn btn-primary">Learn More</a> </div> </div> </div> </div> </div> </section> </main> <footer> <div class="container"> <div class="row"> <div class="col-md-12"> <p>© 2020 Car Vacation. All rights reserved.</p> </div> </div> </div> </footer> <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QLeykU8jmeO+TX3qgNkP0GNIgB6Hp" crossorigin="anonymous"></script> </body> </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值