jquery - Bootstrap 删除警报的不透明度

标签 jquery twitter-bootstrap twitter-bootstrap-3

我正在使用 Bootstrap 模式作为简单的登录表单:

<div class="modal fade login">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body row">        
                <div class="modal-header">
                    <h4>Login panel</h4>
                </div>
                <form class="capture" method="post" name="login">
                    <div class="form-group">
                        <input type="email" name="email" class="form-control" placeholder="Username">
                    </div>
                    <div class="form-group">
                        <input type="password" name="password" class="form-control" placeholder="Password">
                    </div>
                    <button type="button" class="form-group btn btn-default btn-block">Login</button>
                </form>
                <div class="modal-footer"><center><button type="button" class="btn btn-default btn-block" data-dismiss="modal">Close</button></center></div>
            </div>
        </div>
    </div>
</div>

我还使用 jQuery 来处理登录并返回回调,我想使用 boostrap 将其显示为警报框。

这工作正常,但是警报消息受到模式不透明度的影响并且很难看到。

如何使警报消息框出现而不受模态不透明度的影响?

我尝试了以下 CSS:

.notification{
    position: fixed;
    top: 3em;
    left: 20%;
    right: 20%;
    z-index: 1000;
    opacity:0;
}

div如下

<div id="notification"></div>

由以下 jquery 控制,该 jquery 从模态内部触发:

function flash(type,message){
        $(".notification").remove();
        $("#notification").append($("<div class='notification alert alert-" + type + " fade in' data-alert><a class='close' data-dismiss='alert'>×</a><b>"+type.charAt(0).toUpperCase()+type.slice(1)+"</b>: "+message+"</div>"));
        $(".notification").delay(4000).fadeOut("slow", function () { $(this).remove(); });
    }

但是,消息框仍然受到不透明度的阻碍。

最佳答案

您只需将 z-index 稍微调大一些即可。如果您检查 .modal 的样式,您会发现它的 z-index 为 1050。您需要设置您的 z-index 等于或大于该值。

.notification{
    position: fixed;
    top: 3em;
    left: 20%;
    right: 20%;
    z-index: 1051; /* must be equal to or larger than .modal */
    opacity:0;
}

这是一个JSFiddle以供引用。希望这会有所帮助。

关于jquery - Bootstrap 删除警报的不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26999524/

相关文章:

javascript - 移动响应式网页 Accordion

css - 高密度移动设备上的 Bootstrap 3 横向 View

html - 如何在中心垂直对齐两个 div,并在底部保留一个 div?

jQuery 交叉淡入淡出与背景图像

jquery - 如果字段为空,则通过 jQuery 禁用发送按钮

twitter-bootstrap - 执行多响应列时清除行 - Bootstrap

image - 推特 Bootstrap 轮播大小

css - 超大屏幕设备上的全宽横幅尺寸(宽度>1366 像素)

javascript - 在 1 方法中增加变量值会触发另一个方法的 for 循环,欢迎任何建议

javascript - 某些 Bootstrap 类不工作(Bootstrap 4、Navbar 和 bg-)