首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我的覆盖将页面的其余部分向下推,而不是出现在顶部。

我的覆盖将页面的其余部分向下推,而不是出现在顶部。
EN

Stack Overflow用户
提问于 2020-02-23 16:20:39
回答 1查看 1K关注 0票数 0

我想要一个<div>出现在当前屏幕上,当用户点击一个图像,而黑暗的背景后,覆盖。然而,<div>不是出现在当前位置的屏幕顶部,而是将它下面的背景中的所有东西都推入其中。

覆盖前的屏幕截图:

应用覆盖后的屏幕(您可以看到它将其他元素推到下面):

在另一个注意事项上,是否有一种方式,只要点击黑暗的背景(从覆盖),它关闭覆盖?

HTML:

代码语言:javascript
复制
<section id="content">
    <div class="container">
        <section id="grid" class="clearfix">
            <div class="cf show-grid">
                <div class="row">
                <!-- Start Overlay -->
                <div id="overlay"></div>
                <!-- End Overlay -->
                <!-- Start Special Centered Box -->
                <div id="specialBox">
                <button onmousedown="toggleOverlay()">Close Overlay</button>
                </div>
                <!-- End Special Centered Box -->
                <!-- Start Normal Page Content -->
                <div id="wrapper">
                <button onmousedown="toggleOverlay()">Apply Overlay</button>
               </div>
               <!-- End Normal Page Content -->

               <div class="grid-2 dashboardIcons">
                   <h3 class="fontAmaticH1">Stress & Anxiety</h3>
                       <a href="stess-anxiety.php"><img src="images/stress.jpg"></a>
                </div>
                <div class="grid-2 dashboardIcons">
                    <h3 class="fontAmaticH1">Mindfulness</h3>
                       <a class="cursor" onmousedown="toggleOverlay()"><img src="images/mindfulness.jpg"></a>
                </div>

                <div class="grid-2 dashboardIcons">
                     <h3 class="fontAmaticH1">Exam Preperation</h3>
                        <a href="exam-prep.php"><img src="images/examPrep.jpg"></a>
               </div>
            </div>
            </div>
        </section>
    </div>
</section>

CSS:

代码语言:javascript
复制
/*Practising the overlays for modules */
div#overlay {
    display: none;
    z-index: 2;
    background: #000;
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0px;
    left: 0px;
    text-align: center;
}
div#specialBox {
    display: none;
    position: relative;
    z-index: 3;
    margin: 150px auto 0px auto;
    width: 500px; 
    height: 300px;
    background: #FFF;
    color: #000;
}
div#wrapper {
    position:absolute;
    top: 0px;
    left: 0px;
    padding-left:24px;
}

JS:

代码语言:javascript
复制
/* This is for the page overloays within the module pages */
function toggleOverlay(){
  var overlay = document.getElementById('overlay');
    var specialBox = document.getElementById('specialBox');
    overlay.style.opacity = .8;
    if(overlay.style.display == "block"){
        overlay.style.display = "none";
        specialBox.style.display = "none";
    } else {
        overlay.style.display = "block";
        specialBox.style.display = "block";
    }
}

关于信息:我正在使用折叠式网格来确保我的div都是响应的等等。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-23 17:01:13

对于div#specialBox,请尝试如下:

代码语言:javascript
复制
position: fixed;
top: 150px;
left: 50%;
transform: translateX(-50%); /* this will place it in the center */

并将其删除(也适用于div#specialBox__)

代码语言:javascript
复制
position: relative;
margin: 150px auto 0px auto;

虽然div#specialBoxposition: relative,但是块将位于“主流”中,并将rest页面向下推。将fixedabsolute“移除”此流中的块。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60364269

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档