【问题标题】:Input Checkbox cant get clicked输入复选框无法点击
【发布时间】:2021-06-09 08:44:33
【问题描述】:

我正在尝试登录,但我无法选中复选框。

我不知道问题出在哪里。一切看起来都正确并且有效,复选框是唯一不正确的东西。我也没有在网上找到任何东西,所以如果有人能在这里帮助我,那就太好了!

body {
    margin: 0;
    padding: 0;
    background-color: #1a1a1a;
    font-family: Georgia, "Times New Roman", Times, serif;
}

.container {
    background-color: olive;
    height: 500px;
    width: 350px;
    box-shadow: 10px 10px 10px black;
    display: block;
    margin-left: auto;
    margin-right: auto;
    margin-top: 60px;
    margin-bottom: auto;
}

.registerdiv {
    background-color: rgb(110, 110, 1);
    box-shadow: 10px 10px 10px black;
    height: 100px;
    width: 350px;
    margin-left: auto;
    margin-right: auto;
}

.header {
    padding: 20px;
    text-align: center;
    padding-top: 40px;
}

.input {
    width: 250px;
    height: 30px;
    background-color: transparent;
    border-radius: 20px;
    border: 3px solid black;
    outline: thin;
    display: block;
    margin-left: auto;
    margin-right: auto;
    font-size: 15px;
    text-align: center;
    margin-top: 20px;
}

::placeholder {
    color: rgb(46, 46, 46);
    text-align: center;
}

.btn {
    width: 255px;
    height: 33px;
    background-color: black;
    color: white;
    border-radius: 20px;
    border: 3px solid black;
    outline: thin;
    display: block;
    margin-left: auto;
    margin-right: auto;
    font-size: 15px;
    text-align: center;
    margin-top: 20px;
}

label {
    font-size: 15px;
    text-align: center;
    display: block;
    margin-top: -17px;
    margin-left: 30px;
}

.checkbox {
    display: block;
    margin-left: 120px;
    margin-right: auto;
    margin-top: 20px;
    overflow: hidden;
}

.input:focus {
    border: 3px solid rgb(46, 46, 46);
    transition: 0.5s;
}

.input:focus::placeholder {
    color: transparent;
    transition: 0.5s;
}
<body>
    <div class="container">
        <h2 class="header">Sign in</h2>
        <form>
            <input type="text" class="input" placeholder="What's your username?" required />
            <input type="password" class="input" placeholder="What's your password?" required />
            <input type="checkbox" class="checkbox" /><label for="checkbox">Remember me</label>
            <button class="btn" type="submit">Go ahead</button>
        </form>
    </div>
    <div class="registerdiv"></div>
</body>

【问题讨论】:

    标签: html css input checkbox label


    【解决方案1】:

    &lt;label&gt; 标签重叠&lt;input type="checkbox"&gt; 不是您代码中的重要问题。因此,您没有与&lt;input type="checkbox"&gt; 的交互。

    但最好走正确的路:

    您已为&lt;label&gt; 指定for="checkbox" 属性,但忘记为&lt;input type="checkbox"&gt; 指定id="checkbox" 属性。

    由于for属性只引用了another元素的id属性!

    这样做:

    <input id="checkbox" type="checkbox" class="checkbox">
    

    body {
        margin: 0;
        padding: 0;
        background-color: #1a1a1a;
        font-family: Georgia, "Times New Roman", Times, serif;
    }
    
    .container {
        background-color: olive;
        height: 500px;
        width: 350px;
        box-shadow: 10px 10px 10px black;
        display: block;
        margin-left: auto;
        margin-right: auto;
        margin-top: 60px;
        margin-bottom: auto;
    }
    
    .registerdiv {
        background-color: rgb(110, 110, 1);
        box-shadow: 10px 10px 10px black;
        height: 100px;
        width: 350px;
        margin-left: auto;
        margin-right: auto;
    }
    
    .header {
        padding: 20px;
        text-align: center;
        padding-top: 40px;
    }
    
    .input {
        width: 250px;
        height: 30px;
        background-color: transparent;
        border-radius: 20px;
        border: 3px solid black;
        outline: thin;
        display: block;
        margin-left: auto;
        margin-right: auto;
        font-size: 15px;
        text-align: center;
        margin-top: 20px;
    }
    
    ::placeholder {
        color: rgb(46, 46, 46);
        text-align: center;
    }
    
    .btn {
        width: 255px;
        height: 33px;
        background-color: black;
        color: white;
        border-radius: 20px;
        border: 3px solid black;
        outline: thin;
        display: block;
        margin-left: auto;
        margin-right: auto;
        font-size: 15px;
        text-align: center;
        margin-top: 20px;
    }
    
    label {
        font-size: 15px;
        text-align: center;
        display: block;
        margin-top: -17px;
        margin-left: 30px;
    }
    
    .checkbox {
        display: block;
        margin-left: 120px;
        margin-right: auto;
        margin-top: 20px;
        overflow: hidden;
    }
    
    .input:focus {
        border: 3px solid rgb(46, 46, 46);
        transition: 0.5s;
    }
    
    .input:focus::placeholder {
        color: transparent;
        transition: 0.5s;
    }
    <body>
        <div class="container">
            <h2 class="header">Sign in</h2>
            <form>
                <input type="text" class="input" placeholder="What's your username?" required />
                <input type="password" class="input" placeholder="What's your password?" required />
                <input id="checkbox" type="checkbox" class="checkbox" />
                <label for="checkbox">Remember me</label>
                <button class="btn" type="submit">Go ahead</button>
            </form>
        </div>
        <div class="registerdiv"></div>
    </body>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-08
      • 1970-01-01
      • 2016-05-27
      • 1970-01-01
      • 2014-06-02
      相关资源
      最近更新 更多