简体   繁体   English

在固定导航顶栏之前显示div

[英]Show div before fixed navigation top bar

I have a fixed top bar, and now I need to append before this element a div to show a message. 我有一个固定的顶部栏,现在我需要在此元素之前添加一个div来显示一条消息。

Both should be fixed. 两者都应固定。 First the alert message, and then the menu. 首先是警报消息,然后是菜单。 How can i do that? 我怎样才能做到这一点?

<div class="panel-msg">
  Important message here
</div>

<nav id=" mainNav " class="navbar navbar-default navbar-fixed-top " role="navigation ">
  <div class="container ">
    <div class="navbar-header ">
      <h1>
      demo
      </h1>
    </div>
  </div>
</nav>
<div class="demo ">
</div>

Demo 演示

z-index is possible only with positioning so give the class panel-msg absolute position and a z-index higher than that of navbar like this: z-index仅在定位时才有可能,因此请给class panel-msg绝对位置,并赋予z-index高于navbar如下所示:

 .panel-msg{
      position:absolute;
      z-index:222222;
      top:0px;
    }

It looks like when you use "navbar navbar-default navbar-fixed-top" it will override any changes you make and always put that navbar at the top. 看起来,当您使用“ navbar navbar-default navbar-fixed-top”时,它将覆盖您所做的所有更改,并且始终将该navbar放在顶部。 If you remove the word "top" it will show the msg panel. 如果删除“顶部”一词,它将显示味精面板。

Here's your example with an alert message above: http://jsfiddle.net/sawqv3gp/ 这是上面带有警报消息的示例: http : //jsfiddle.net/sawqv3gp/

But it loses it's fixed positioning. 但它失去了固定的位置。 So you might want to try a different layout altogether. 因此,您可能希望完全尝试其他布局。

I would recommend changing your design to allow for a "navbar header" and using the Bootstrap alert function (also always the user to close the alert). 我建议您更改设计以允许使用“导航栏标题”,并使用Bootstrap警报功能(也总是用户关闭警报)。

Here's an example: http://www.bootply.com/4FSUjc2qej 这是一个示例: http : //www.bootply.com/4FSUjc2qej

<div class="alert alert-info" role="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Holy guacamole!</strong> Best check yo self, you are looking very good.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM