You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现点击登录按钮后登录区域完全覆盖注册区域?

登录区域完全覆盖容器的修改方案

导致登录区域无法完全覆盖注册区域的核心问题:

  • .login高度小于容器高度(460px vs 500px)
  • 使用固定像素值做位移,无法精准匹配容器高度
  • 顶部圆角设置导致视觉上无法填满容器

修改步骤:

  1. 将.login的高度设为100%,使其完全填充父容器.main
  2. 让.login的圆角与.main保持一致,避免顶部圆角露出下方内容
  3. 将选中状态下的位移从固定像素值改为-100%,确保.login完全覆盖.signup
  4. 可选:在选中状态下隐藏.signup内容,彻底避免露出

修改后的完整CSS代码:

body{
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: 'Jost', sans-serif;
background: linear-gradient(to bottom, #e57373, #ffb74d, #cfd8dc);
}
.main{
    width: 350px;
    height: 500px;
    background: red;
    overflow: hidden;
    background: url("https://doc-08-2c-docs.googleusercontent.com/docs/securesc/68c90smiglihng9534mvqmq1946dmis5/fo0picsp1nhiucmc0l25s29respgpr4j/1631524275000/03522360960922298374/03522360960922298374/1Sx0jhdpEpnNIydS4rnN4kHSJtU1EyWka?e=view&authuser=0&nonce=gcrocepgbb17m&user=03522360960922298374&hash=tfhgbs86ka6divo3llbvp93mg4csvb38") no-repeat center/ cover;
    border-radius: 10px;
    box-shadow: 5px 20px 50px #000;
}
#chk{
    display: none;
}
.signup{
    position: relative;
    width:100%;
    height: 100%;
}
label{
    color: #fff;
    font-size: 2.3em;
    justify-content: center;
    display: flex;
    margin: 60px;
    font-weight: bold;
    cursor: pointer;
    transition: .5s ease-in-out;
}
input{
    width: 60%;
    height: 20px;
    background: #e0dede;
    justify-content: center;
    display: flex;
    margin: 20px auto;
    padding: 10px;
    border: none;
    outline: none;
    border-radius: 5px;
}
button{
    width: 50%;
    height: 40px;
    margin: 10px auto;
    justify-content: center;
    display: block;
    color: #fff;
    background: #573b8a;
    font-size: 1em;
    font-weight: bold;
    margin-top: 20px;
    outline: none;
    border: none;
    border-radius: 15px;
    transition: .2s ease-in;
    cursor: pointer;
}
button:hover{
    background: #6d44b8;
}
.login{
    height: 100%; /* 修改为100%高度 */
    background: #eee;
    border-radius: 10px; /* 和容器保持一致的圆角 */
    transform: translateY(-180px);
    transition: .8s ease-in-out;
}
.login label{
    color: #573b8a;
    transform: scale(.6);
}

#chk:checked ~ .login{
    transform: translateY(-100%); /* 用百分比位移,完全覆盖下方内容 */
}
#chk:checked ~ .login label{
    transform: scale(1);    
}
#chk:checked ~ .signup{
    opacity: 0; /* 可选:隐藏注册区域内容,彻底避免露出 */
    visibility: hidden;
}
#chk:checked ~ .signup label{
    transform: scale(.6);
}

关键修改说明:

  • height: 100%:让登录区域高度与容器完全匹配
  • transform: translateY(-100%):基于自身高度向上位移,确保完全覆盖注册区域
  • 新增的.signup选中状态样式:通过opacity和visibility彻底隐藏注册区域内容,消除任何视觉上的露出

内容的提问来源于stack exchange,提问作者BIOMBROCK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 19:50:01