简体   繁体   English

不透明或页面背景显示在弹出窗口的一半页面上

[英]Opacity or Page Background is showing on half page on Pop Up

I am making a pop up on one of my project. 我正在弹出我的一个项目。

CSS Code CSS代码

<style type="text/css">
    #modalPage
    {
      display: none;
      position: absolute;
      width: 100%;
      height: 100%;
      top: 0px;
      left: 0px;
      background-color: rgba(0, 0, 0, 0.95);
      z-index: 999;
    }
    .modalContainer
    {
      position: absolute;
      width: 100%;
      height: 100%;
      left: 50%;
      top: 50%;
      z-index: 999;
    }
    </style>

Content CSS 内容CSS

.modal
    {
      background-color: #6f9255;
      position: relative;
      top: -300px;
      left: -305px;
      z-index: 1000;
      width: 600px;
      overflow:auto;

    }

JAVASCRIPT Code JAVASCRIPT代码

<script type="text/javascript">
function myFunction() {
     document.getElementById('modalPage').style.display = "block";

}

function hideModal()
    {
      document.getElementById('modalPage').style.display = "none";
    }
</script>

HTML Code HTML代码

<div id="modalPage">
      <div class="modalContainer">
        <div class="modal"> </div>
      </div>
</div>

But the problem is that, it is fine but the opacity or page background which I putting on it, it is displaying on half page, not on full page. 但是问题是,这很好,但是我放在上面的不透明度或页面背景却显示在半页上,而不是整页上。 Displaying by this code. 通过此代码显示。 background-color: rgba(0, 0, 0, 0.95); Please tell me, where is the problem. 请告诉我,问题出在哪里。

I can't keep the position fixed, because my pop up is longer then original page size and it is coming with scroll and cross the footer link too. 我无法固定位置,因为我的弹出窗口的长度比原始页面的大小还要长,并且它随滚动一起滚动并穿过页脚链接。

Any help will be appreciated. 任何帮助将不胜感激。

Thanks 谢谢

I think the problem is not related with an opacity issue. 我认为该问题与不透明性问题无关。 You say that your .modalContainer is 100% width and height but you start it at 50% top left. 您说您的.modalContainer的宽度和高度为100%,但您从左上角的50%开始。 So the whole thing is 150% width and height, while #modalPage is only 100% width and height. 所以整个事情是150%的宽度和高度,而#modalPage只是100%的宽度和高度。

If you know the exact width and height of your container I suggest you to simply modify your css to center propertly the container. 如果您知道容器的确切宽度和高度,建议您简单地修改css使其正确居中。 For example: 例如:

.modalContainer
    {
      position: absolute;
      width: 50%;
      height: 50%;
      left: 25%;
      top: 25%;
      z-index: 999;
      background-color: red; /*added to see where the container is*/
    }

Working example: http://jsfiddle.net/L2cXP/ 工作示例: http : //jsfiddle.net/L2cXP/

If you want a modal longer than the page itself, i suggest a new approach. 如果您想要一个比页面本身更长的模式,我建议一种新方法。

We can ignore vertical centering because the modal is longer than the page. 我们可以忽略垂直居中,因为模态比页面长。 We just want that #modalPage has a overflow: auto property so it will show a scrollbar when its contents are longer than it. 我们只希望#modalPage具有溢出:auto属性,以便当其内容长于其时将显示滚动条。

Probably you would like to add an overflow: hidden property to the body when the modal shows to block the standard scrollbar of your page. 可能您希望在模式显示为阻塞页面的标准滚动条时向主体添加一个overflow:hidden属性。

Check this working example: http://jsfiddle.net/L2cXP/1/ 检查此工作示例: http : //jsfiddle.net/L2cXP/1/

try: 尝试:

#modalPage {
    position: fixed;
}

http://jsfiddle.net/68Sty/ http://jsfiddle.net/68Sty/

.modalContainer has a "left" of 50%, so starting at halfway is expected. .modalContainer的“左”值为50%,因此应从中间开始。 Try something like: 尝试类似:

.modalContainer {
    position: absolute;
    width: 100%;
    height: 100%;
    top:0;
    left:0;
    right:0;
    bottom:0;
    z-index: 999;
}

try this 尝试这个

<div id="modalPage">
    <div class='relative'>
        <div class="modalContainer">
           <div class="modal"> </div>
        </div>
    </div>
</div>

your css 你的CSS

 .relative{
     position:relative;
     zoom:1;
     height:100%; 
     width:100%;
 }

A little CSS magic - and we have simple and nice CSS popups with no javascript positioning! 一点CSS魔术-我们有简单而漂亮的CSS弹出窗口,没有javascript定位! consider this demo: 考虑这个演示:

HTML: HTML:

<div id="modalPage" class="csspopup-overlay">
    <div class="modalContainer csspopup-popup">
        <div class="csspopup-close" onclick="hideModal()">&times;</div>
        <div class="modal">Some modal content</div>
    </div>
</div>

I define .csspopup-overlay and .csspopup-popup in CSS as follows: 我在CSS中定义了.csspopup-overlay.csspopup-popup ,如下所示:

.csspopup-overlay {
        position: fixed;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, .5);
        text-align: center;
}
.csspopup-overlay:after, .csspopup-valignfix {
        display: inline-block;
        *display: inline;
        *zoom: 1;
        height: 100%;
        width: 0;
        vertical-align: middle;
        content: '';
}
.csspopup-popup {
        display: inline-block;
        *display: inline;
        *zoom: 1;
        position: relative;
        max-width: 80%;
        padding: 15px;
        box-shadow: 0 0 15px 5px rgba(0, 0, 0, 0.3);
        background: #FFF;
        vertical-align: middle;
        border-radius: 6px;
}
.csspopup-popup > .csspopup-close {
        display: block;
        position: absolute;
        top: -15px;
        right: -12px;
        width: 12px;
        height: 12px;
        padding: 4px;
        border: 4px solid #fff;
        border-radius: 50%;
        box-shadow: inset 0 2px 2px 2px rgba(0, 0, 0, 0.2), 0 2px 5px rgba(0, 0, 0, .4);
        cursor: pointer;
        background: #555;
        color: #FFF;
        text-align: center;
        font-size: 12px;
        line-height: 12px;
        text-decoration: none;
        font-weight: bold
}

Demo: http://jsfiddle.net/acA73/ 演示: http//jsfiddle.net/acA73/

Note: I extracted these CSS for you from https://github.com/dfsq/cssPopup jQuery plugin. 注意:我从https://github.com/dfsq/cssPopup jQuery插件为您提取了这些CSS。

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

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