【问题标题】:Make Bootstrap static-navbar overlay content like fixed-navbar制作 Bootstrap 静态导航栏覆盖内容,如固定导航栏
【发布时间】:2015-05-13 17:58:48
【问题描述】:

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

我想要什么

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

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

  1. 当导航栏在移动视图中折叠时,汉堡图标会显示导航栏链接,而不会按下英雄部分。

发生了什么

  1. 使用“静态”将导航栏部分堆叠在英雄部分之前,而不是覆盖它
  2. 按下汉堡图标会下推英雄部分而不是覆盖它

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

我的 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”。

【问题讨论】:

  • 绝对/相对定位?
  • @aibrean 很棒,工作! - 编辑了我的问题
  • 如有疑问,请定位 LOL。
  • 我可以建议你写一个详细说明你的解决方案的答案,而不是把它放在答案/cmets 中。它使有类似问题的潜在用户更容易看到有解决方案。当人们为您的好答案投票时,您还会获得神奇的独角兽积分(也称为声誉):)
  • 是的,您应该为此写一个答案,这样它就不会再出现未回答的情况。

标签: twitter-bootstrap twitter-bootstrap-3 navbar


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我知道这是一个旧线程,但我遇到了同样的问题,我将导航栏绝对定位,导航栏右侧的链接位于左侧。

    【讨论】:

    • 我相信我可以找到几种同样合理的方法来应用答案中所述的内容。如果发布了代码的更正版本,那将使答案更有用。
    猜你喜欢
    • 1970-01-01
    • 2015-02-03
    • 2016-09-04
    • 1970-01-01
    • 2016-03-13
    • 2015-11-03
    • 2015-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多