大神回答一下这个问题?

让导航条固定在顶部给body设置了padding-top:70px 为啥还是会遮住内容呢?请大家复制我的代码帮我看一下谢谢了

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>现代浏览器博物馆</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!--[if lt IE 9]>
      <script src="js/html5shiv.js"></script>
      <script src="js/respond.min.js"></script>
    <![endif]-->
    <style>
       body{
           padding-top:70px;
       }
    </style>
  </head>
  <body>
   <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  <div>
    <!-- Brand and toggle get grouped for better mobile display -->
    <div>
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span>Toggle navigation</span>
        <span></span>
        <span></span>
        <span></span>
      </button>
      <a href="#">现代浏览器博物馆</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><a href="#">综述</a></li>
        <li><a href="#">简述</a></li>
        <li>
          <a href="#" data-toggle="dropdown">特点 <span></span></a>
          <ul role="menu">
            <li><a href="#feature-tab" data-tab="tab-chrome">Chrome</a></li>
            <li><a href="#feature-tab" data-tab="tab-firefox">Firefox</a></li>
            <li><a href="#feature-tab" data-tab="tab-safari">Safari</a></li>
            <li><a href="#feature-tab" data-tab="tab-opera">Opera</a></li>
            <li><a href="#feature-tab" data-tab="tab-ie">IE</a></li>
          </ul>
        </li>
        <li><a href="#">关于</a></li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
<p>dfghjkjhgfds</p>
<p>1111111111111</p>
<p>2222222222222222222222</p>
<p>dfghjkjhgfds</p>
<p>1111111111111</p>
<p>2222222222222222222222</p>
<p>dfghjkjhgfds</p>
<p>1111111111111</p>
<p>2222222222222222222222</p>
<p>dfghjkjhgfds</p>
<p>1111111111111</p>
<p>2222222222222222222222</p>
<p>dfghjkjhgfds</p>
<p>1111111111111</p>
<p>2222222222222222222222</p>
<p>dfghjkjhgfds</p>
<p>1111111111111</p>
<p>2222222222222222222222</p>
<p>dfghjkjhgfds</p>
<p>1111111111111</p>
<p>2222222222222222222222</p>
<p>dfghjkjhgfds</p>
<p>1111111111111</p>
<p>2222222222222222222222</p>
<p>dfghjkjhgfds</p>
<p>1111111111111</p>
<p>2222222222222222222222</p>
<p>dfghjkjhgfds</p>
<p>1111111111111</p>
<p>2222222222222222222222</p>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="js/jquery-1.11.1.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>


慕粉笑眯眯爱生活
浏览 2376回答 3
3回答

幕布斯7574896

因为你的导航栏不符合bootstrap的规范,导致元素错位。你要是设置padding-top一个足够大的数字,也是可以显示的,不过这也是错误的,正确的方式还是添加相应类名:<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">   <div class="navbar-header>     <!-- Brand and toggle get grouped for better mobile display -->     <div>       <button type="button" class="navbar-toggle" data-toggle="collapse"                 data-target="#example-navbar-collapse">             <span class="sr-only">切换导航</span>             <span class="icon-bar"></span>             <span class="icon-bar"></span>             <span class="icon-bar"></span>       </button>       <a class="navbar-brand" href="#">现代浏览器博物馆</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><a href="#">综述</a></li>         <li><a href="#">简述</a></li>         <li class="dropdown">           <a class="dropdown-toggle" href="#" data-toggle="dropdown">特点 <span class="caret"></span></a>           <ul class="dropdown-menu" role="menu">             <li><a href="#feature-tab" data-tab="tab-chrome">Chrome</a></li>             <li><a href="#feature-tab" data-tab="tab-firefox">Firefox</a></li>             <li><a href="#feature-tab" data-tab="tab-safari">Safari</a></li>             <li><a href="#feature-tab" data-tab="tab-opera">Opera</a></li>             <li><a href="#feature-tab" data-tab="tab-ie">IE</a></li>           </ul>         </li>         <li><a href="#">关于</a></li>       </ul>     </div><!-- /.navbar-collapse -->   </div><!-- /.container-fluid --> </nav>

qq_爱妾别闹_0

position:fixed;
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Bootstrap