简体   繁体   English

Div 下拉菜单

[英]Div sliding down menu

Well, this is actually a complicated problem, the default behavior of a header is simple, it gets in front of everything, however I want to put a div that will overlap it, putting a blur on the page, my goal is for the header to be behind of this div.嗯,这实际上是一个复杂的问题,标题的默认行为很简单,它位于所有内容的前面,但是我想放置一个将其重叠的 div,在页面上放置模糊,我的目标是标题落后于这个 div。

 .body{ min-height: 2000px; } .overlay{ background-color: rgba(126, 246, 53, 0.50); z-index: 1050; position: absolute; height: 100%; width: 100%; top: 0; } .overlayDiv{ background: white; z-index: 1051; margin-top: 100px; position: relative; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> <nav class="navbar fixed-top navbar-light bg-light"> <a class="navbar-brand" href="#">Header</a> </nav> <div class="body"> <div class="overlayDiv col-8 offset-2"> <h1>That's divs on top of the page</h1> </div> <div class="overlay"></div> </div>

As you can see in the example, overlayDiv is above the overlay , which is what I want, but it goes over the menu, what I want is for the menu to be over it even being opaque, would that be possible?正如您在示例中所看到的, overlayDiv位于overlay之上,这正是我想要的,但它越过菜单,我想要的是菜单在它上方甚至是不透明的,这可能吗?

Edit:编辑:

I would like to do something rather complicated, I will explain otherwise to try to clarify.我想做一些相当复杂的事情,我会以其他方式解释以试图澄清。

The top div has to go under the header when it gets there, and fade in behind it partially.顶部 div 到达那里时必须位于标题下方,并部分淡入其后面。

so it looks like it's entering the page just below the header, I thought of going to cut the height of her, but the content is not getting the way desired, example: cutting the text所以看起来它正在进入页眉正下方的页面,我想削减她的高度,但内容没有得到想要的方式,例如:削减文本

Edit 2.0:编辑 2.0:

The div of the text displayed in the example really has to be above the mask, and the menu below the mask.示例中显示的文本的 div 确实必须在蒙版上方,而菜单在蒙版下方。

The idea is that as div reaches the height of the menu it slowly moves past it, as if sliding down the menu这个想法是,当 div 到达菜单的高度时,它会慢慢移过它,就像向下滑动菜单一样

would look something like this看起来像这样

在此处输入图片说明

If I understand you correctly, you want the navbar between overlayDiv and overlay ?如果我理解正确的话,您想要overlayDivoverlay之间的导航栏吗? You can do this by adjusting the z-index es.您可以通过调整z-index来做到这一点。 navbar gets a default z-index of 1030 , so set overlayDiv 's z-index to something higher, and overlay 's to something lower: navbar的默认z-index1030 ,因此将overlayDivz-index为更高的值,并将overlay的值设置为更低的值:

 .body{ min-height: 2000px; z-index: 99; } .overlay{ background-color: rgba(126, 246, 53, 0.50); position: absolute; height: 100%; width: 100%; top: 0; z-index: 97; } .overlayDiv{ background: white; z-index: 5000; margin-top: 100px; position: relative; z-index: 98; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> <nav class="navbar fixed-top navbar-light bg-light"> <a class="navbar-brand" href="#">Header</a> </nav> <div class="body"> <div class="overlayDiv col-8 offset-2"> <h1>That's divs on top of the page</h1> </div> <div class="overlay"></div> </div>

Edit: z-index is the right way of usage in this particular case.编辑: z-index 在这种特殊情况下是正确的使用方式。

Please check is it something you want i guess.请检查它是你想要的东西,我猜。

 .body{ min-height: 2000px; } nav.fixed-top{ z-index: 1050; background: #fff; box-shadow: 0 0 8px rgba(0,0,0,0.3); } .overlay{ background-color: rgba(126, 246, 53, 0.50); z-index: 1060; position: absolute; height: 100%; width: 100%; top: 0; } .overlayDiv{ background: white; z-index:1040; margin-top: 100px; position: relative; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> <nav class="navbar fixed-top navbar-light"> <a class="navbar-brand" href="#">Header</a> </nav> <div class="body"> <div class="overlayDiv col-8 offset-2"> <h1>That's divs on top of the page</h1> </div> <div class="overlay"></div> </div>

Simply add <div class="BlurDiv"> </div>只需添加<div class="BlurDiv"> </div>

Place the div around the entire html, so whatever your top container div is for example if it was <div class="main-container"></div>将 div 放在整个 html 周围,因此无论您的顶部容器 div 是什么,例如,如果它是<div class="main-container"></div>

Make it like this:让它像这样:

<div class="BlurDiv">
  <div class="main-container">
  </div>
</div>

then create your blur CSS and assign it to div id BlurDiv.然后创建您的模糊 CSS 并将其分配给 div id BlurDiv。

There is one other solution i found bit tricky but meet requirement, i am adding a same background to nav as overlay .还有一个我发现有点棘手但满足要求的其他解决方案,我向nav添加了与overlay相同的background Now it will show white background on text as well as getting under 'nav'.现在它将在文本上显示白色背景以及进入“导航”。 This will also allow you to click on nav elements.这也将允许您单击nav元素。

 .body { min-height: 2000px; } nav.fixed-top { z-index: 1080; background: #befa99; box-shadow: 0 0 8px rgba(0, 0, 0, 0.3); } .overlay { background-color: rgba(126, 246, 53, 0.50); z-index: 1030; position: absolute; height: 100%; width: 100%; top: 0; } .overlayDiv { background: white; z-index: 1040; margin-top: 100px; position: relative; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> <nav class="navbar fixed-top navbar-light"> <a class="navbar-brand" href="#">Header</a> </nav> <div class="body"> <div class="overlayDiv col-8 offset-2"> <h1>That's divs on top of the page</h1> </div> <div class="overlay"></div> </div>

Based on your answers I was able to think of a solution that was plausible to solve the problem, thank you for your commitment, what I needed is below根据您的回答,我能够想到一个可行的解决方案来解决问题,感谢您的承诺,我需要的是下面

 .body{ min-height: 2000px; } .overlay{ background-color: rgba(126, 246, 53, 0.50); z-index: 1028; position: absolute; height: 2000px; width: 100%; top: 0; } .overlayDiv{ background: white; z-index: 1029; margin-top: 100px; position: relative; } .navOverlayDiv{ background-color: rgba(126, 246, 53, 0.50); z-index: 1053; position: absolute; height: 100%; width: 100%; top: 0; left: 0; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> <nav class="navbar fixed-top navbar-light bg-light"> <a class="navbar-brand" href="#">Header</a> <div class="navOverlayDiv"> </div> </nav> <div class="body"> <div class="overlayDiv col-8 offset-2"> <h1>That's divs on top of the page</h1> </div> <div class="overlay"></div> </div>

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

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