无法单击带有负z-index的文本框 [英] Unable to click textbox with negative z-index

查看:181
本文介绍了无法单击带有负z-index的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在屏幕中间有一个文本框,但当我点击它时,没有注册点击。我认为这是一个CSS Z-Index问题。如何诊断和修复此问题?

I have a textbox in the middle of the screen, but when I click on it, no clicks are registered. I think it's a CSS Z-Index issue. How do I go about diagnosing and fixing this issue?

JsFiddle

div#container {
    z-index:-1;
    position:relative;
    height:300px;
    width:300px;
    margin:0 auto;
    background-color: #E9E9E9;
    box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.25);
    padding-top: 8px;
}
h2 {
    text-align:center;
}
#container input[type="submit"] {
    position:absolute;
    bottom:0;
    left:0;
    height:50px;
    width:100%;
}
#container input[type="text"], #container input[type="password"] {
    position:absolute;
    outline:0;
    border:none;
    padding:0;
    margin:0;
    height:50px;
    top:50px;
    width:100%;
}
#container input[type="password"] {
    top:150px;
}
.overlay {
    position:absolute;
    top:0;
    left:0;
    z-index:2;
    height:100%;
    width:100%;
    background:gray;
    text-align:center;
    line-height:300px;
    box-shadow:inset 0 120px 0 0 darkgray, inset 0 122px 0 0 gray, inset 0 124px 0 0 darkgray, inset 0 -120px 0 0 darkgray, inset 0 -122px 0 0 gray, inset 0 -124px 0 0 darkgray;
}
body:hover .overlay {
    display:none;
}

<div id="container">
     <h2>LOGIN</h2>

    <input type="text" id="name" placeholder="Enter your Name" />
    <input type="password" id="password" placeholder="Enter your Password" />
    <input type="submit" id="submit" value="Login" />
    <div class="overlay">LOGIN HERE</div>
</div>

我的问题是,我实际上不能点击输入。我试着玩的布局,但我似乎不能得到输入'可点击'。

My issue is that I can't actually click on the inputs. I have tried playing around with the layout, but I can't seem to get the inputs 'clickable'.

有人可以解释如何解决这个问题吗?

Could someone explain how this issue could be resolved?

推荐答案

问题是 z-index c $ c> div#container 元素分配为-1。

The issue is with the z-index property of div#container element assigned as -1.

将元素的z-index设置为更高的值,例如1000等。

Set the z-index for the element to some higher value like 1000 etc.

div#container {

    background-color: #E9E9E9;
    box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.25);
    clear: left;
    height: 75px;
    margin: 0 auto 13px;
    overflow: auto;
    padding-top: 8px;
    position: relative;
    text-align: center;
    width: 510px;
    z-index: 1000;
}

这篇关于无法单击带有负z-index的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆