【问题标题】:HTML modal-dialog box does not load properlyHTML 模式对话框无法正确加载
【发布时间】:2015-11-11 04:11:08
【问题描述】:

我正在尝试在 html 中的 href 单击上添加模式框。 HTML的代码是:

<a href="#openModal">Open Modal</a>

<div id="openModal" class="modalDialog">

</div>
<a href="#openModal">Open Modal</a>

<div id="openModal" class="modalDialog">
    <div>
        <a href="#close" title="Close" class="close">X</a>
        <h2>Modal Box</h2>
        <p>This is a sample modal box that can be created using the powers of CSS3.</p>
        <p>You could do a lot of things here like have a pop-up ad that shows when your website loads, or create a login/register form for users.</p>
    </div>
</div>

下面是我应用到我的对话框的 CSS:

.modalDialog {
    position: fixed;
    font-family: Arial, Helvetica, sans-serif;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0,0,0,0.8);
    z-index: 99999;
    opacity:0;
    -webkit-transition: opacity 1000ms ease-in;
    -moz-transition: opacity 400ms ease-in;
    transition: opacity 400ms ease-in;
    pointer-events: none;
}

.modalDialog:target {
    opacity:1;
    pointer-events: auto;
}

.modalDialog > div {
    width: 400px;
    position: relative;
    margin: 10% auto;
    padding: 5px 20px 13px 20px;
    border-radius: 10px;
    background: #fff;
    background: -moz-linear-gradient(#fff, #999);
    background: -webkit-linear-gradient(#fff, #999);
    background: -o-linear-gradient(#fff, #999);
}

.close {
    background: #606061;
    color: #FFFFFF;
    line-height: 25px;
    position: absolute;
    right: -12px;
    text-align: center;
    top: -10px;
    width: 24px;
    text-decoration: none;
    font-weight: bold;
    -webkit-border-radius: 12px;
    -moz-border-radius: 12px;
    border-radius: 12px;
    -moz-box-shadow: 1px 1px 3px #000;
    -webkit-box-shadow: 1px 1px 3px #000;
    box-shadow: 1px 1px 3px #000;
}

.ui-widget-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
.ui-front {
    z-index: 100;
}

正如预期的那样,在单击“模型打开”链接时,我应该能够看到一个模态弹出窗口,其中包含正文。 但是,我的屏幕看起来像一个没有任何正文的打开模式(没有正文内容和关闭图标)。

见附图。它显示了模态在打开时的外观。背景被禁用,因为它应该是。

谁能告诉我哪里出错了?

提前致谢。

【问题讨论】:

  • 您发布的代码有两个ID相同的链接。也许这是一个错字,但如果不是,ID 必须是唯一的。我无法复制这个问题。您的代码似乎在这里工作:jsfiddle.net/reqwptnx
  • 一个可悲且非常糟糕的错字是@Cory。非常感谢您纠正它:)

标签: javascript jquery html modal-dialog


【解决方案1】:

那是因为您打开了一个具有相同 id 的空容器 如果你删除下面的空 div 它工作正常

<div id="openModal" class="modalDialog">

</div>

请看这里:http://jsfiddle.net/s6zn93ze/1/

【讨论】:

  • 谢谢尼克。像这样一个简单的错误消耗了我的时间。
猜你喜欢
  • 2021-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多