使用 Bootstrap 3。我有一个具有背景图案的全屏英雄/介绍部分。

我想要什么 :

  • 覆盖此英雄部分的静态导航栏,以便英雄部分的背景图案显示在导航栏的背景中(就像我使用“navbar-fixed-top”而不是“navbar-static-top”一样)。

  • 我希望它看起来像什么(导航栏固定顶部样式):

  • 当导航栏在移动 View 中折叠时,汉堡图标会显示导航栏链接,而不会向下推英雄部分。



  • 发生了什么 :
  • 在英雄部分之前使用“静态”堆栈导航栏部分而不是覆盖它
  • 按汉堡图标会向下推英雄部分而不是覆盖它

  • 知道如何在不给英雄部分负边距的情况下做到这一点吗?

    我的 HTML:
    <nav class="navbar navbar-static-top" role="navigation"> 
        <div class="container"> 
            <div class="navbar-header"> 
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-main-collapse"> 
                    <i class="fa fa-bars"></i> 
                </button> 
                <div class="navbar-brand" href="#page-top"> 
                    <img src="http://placehold.it/200x80" alt=" Logo" width="100"> 
                </div> 
            </div> 
     
            <!-- Collect the nav links, forms, and other content for toggling --> 
            <div id="navbar-main-collapse" class="collapse navbar-collapse navbar-right"> 
                <ul class="nav navbar-nav"> 
                    <li class="active"><a href="..." target="_blank"><i class="fa fa-folder-open"></i> Link 1</a></li> 
                </ul> 
            </div> 
            <!-- /.navbar-collapse --> 
        </div> 
        <!-- /.container --> 
    </nav> 
     
    <section id="hero" class="full-screen-section"> 
        <div class="cell-mid"> 
            <div class="section-body"> 
                <div class="container"> 
                    <div class="row"> 
                        <div class="col-md-2 col-md-offset-1 text-right"> 
                            <img src="http://placehold.it/300x120" id="faceOne" class="img-max hidden-xs hidden-sm"> 
                        </div> 
                        <div class="col-md-6 text-left"> 
                            <h1 class="brand-heading">EXAMPLE HEADING</h1> 
                        </div> 
                        <div class="col-md-2 text-left"> 
                            <img src="http://placehold.it/300x120" id="faceTwo" class="img-max hidden-xs hidden-sm"> 
                        </div> 
                    </div> 
                </div> 
            </div> 
        </div> 
    </section> 
    

    我的 CSS:
    /* --------------- Nav --------------- */ 
     
    .navbar { 
        padding: 1em 0; 
        margin-bottom: 0; 
        border: none; 
        text-transform: uppercase; 
        background-color: transparent; 
        background-image: none; 
    } 
     
    .navbar a { 
        color:#fff; 
    } 
     
    /* --------------- Hero --------------- */ 
     
    #hero { 
        display: table; 
        width: 100%; 
        height: 100%; 
        padding: 200px 0 50px 0; 
        text-align: center; 
        color: #fff; 
        background: linear-gradient( 
          rgba(248, 153, 153, 0.68),  
          rgba(248, 153, 153, 0.68)), url('bg-science.png'); 
        -webkit-box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.5); 
        -moz-box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.5); 
        box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.5); 
    } 
    

    编辑 :
    感谢@airbean,找到了解决方案。刚刚使用了 navbar-fixed-top 类并在 navbar 类上添加了“position:absolute”。

    请您参考如下方法:

    @Aibrea 提供了帮助。我使用了 navbar-fixed-top 类并在 navbar 类上添加了“position:absolute”。


    评论关闭
    IT干货网

    微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!