导航栏位于标题之上

时间:2011-08-26 13:15:59

标签: css

我有以下CSS代码,我的问题是我的 导航栏位于我的标题栏之上。我该怎么办 导航栏从标题直接向下?

header {                                                                                
    background: black;                                                                  
    height: 60px;                                                                       
    left: 0;                                                                            
    margin: 0;                                                                          
    padding: 0;                                                                         
    position: absolute;                                                                 
    width: 100%;                                                                        
}                                                                                       

header img {                                                                            
    float: left;                                                                        
    margin-right: 10px;                                                                 
    position: relative;                                                                 
}                                                                                       

header h1 {                                                                             
    color: white;                                                                       
    font: 26px Helvetica, Arial, sans-serif;                                            
    line-height: 60px;                                                                  
    margin: 0;                                                                          
    vertical-align: middle;                                                             
}                                                                                       

nav {                                                                                   
    background: black;                                                                  
    margin: 0;                                                                          
    padding: 0;                                                                         
    position: absolute;                                                                 
    width: 100%;                                                                        
}

3 个答案:

答案 0 :(得分:2)

为导航设置一个与导航栏高度相同的边距顶部。

nav { 
 background: black;
 margin: 0;
 margin-top:60px;
 padding: 0;
 position: absolute;
 width: 100%;
}

答案 1 :(得分:0)

@ H.A;您将position absolute提交到header块& nav阻止。因此,当您将position absolute提供给元素时,则元素将删除正常流

CSS:

nav { 
 top:60px;
 padding: 0;
 position: absolute;
 width: 100%;
}

阅读本文了解更多http://css-tricks.com/791-absolute-positioning-inside-relative-positioning/

答案 2 :(得分:0)

<!DOCTYPE html>
<html >
  <head>
    <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <style>
 .navbar-fixed-top{ 

 position:static;

}
</style>
  </head>

  <body>
 <div class="row">
            <div class="col-lg-12">
                <div class="intro-message">
                    <h1>HOST</h1>
                    <h3>two is better than one</h3>
                    <hr class="intro-divider">
                    <ul class="list-inline intro-social-buttons">
                        <li>
                            <a href="https://twitter.com/SBootstrap" class="btn btn-default btn-lg"><i class="fa fa-twitter fa-fw"></i> <span class="network-name">Twitter</span></a>
                        </li>
                        <li>
                            <a href="https://github.com/IronSummitMedia/startbootstrap" class="btn btn-default btn-lg"><i class="fa fa-github fa-fw"></i> <span class="network-name">Github</span></a>
                        </li>
                        <li>
                            <a href="#" class="btn btn-default btn-lg"><i class="fa fa-linkedin fa-fw"></i> <span class="network-name">Linkedin</span></a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
 </div>   


   <nav class="navbar navbar-default navbar-fixed-top topnav" role="navigation">
        <div class="container topnav">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <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 topnav" href="/">Host</a>
            </div>

        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav navbar-right">
                <li>
                    <a href="#">Login</a>
                </li>
                <li>
                    <a href="#">Sign up</a>
                </li>
            </ul>

            <form class="navbar-form navbar-right" role="search">
              <div class="form-group">
                <input type="text" class="form-control" placeholder="Search">
              </div>
              <button type="submit" class="btn btn-default">Submit</button>
            </form>

        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav> 


  </body>
</html>