输入复选框无法点击

Input Checkbox cant get clicked

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

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

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>

<label> 标记 <input type="checkbox"> 重叠 不是您代码中的重要问题。因此,您无法与 <input type="checkbox">.

进行交互

但最好走对路:

您已为 <label> 指定 for="checkbox" 属性,但忘记为 <input type="checkbox"> 指定 id="checkbox" 属性。

因为for属性只引用了另一个元素的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>