登录表单文本框不会消失



我为一个uni项目创建了这个简单的登录表单,由于某种原因,文本字段周围的框仍然显示,我希望它不可见。表单是如何工作的;当用户点击任意一个字段时,占位符就会上升,并在其下方键入(参见屏幕截图(然而,由于某种原因,文本框仍然存在。如有任何帮助,我们将不胜感激。

.center {
position:fixed;
top: 40%;
left: 70%;
transform: translate(-50%, -50%);
width: 720px;
height: 350px;
background: linear-gradient(180deg, white, silver );
size: 100%;
border-style: solid;
border-color: black;
border-width: 1px;

}

.center h1{
text-align: center;
padding: 0 0 20px 0;
border-bottom: 1px solid silver;
}

.center form {
padding: 0 40px;
}

form .txt_field {
position: relative;
border-bottom: 2px solid #adadad;
margin: 30px 0;
}

.txt-field input {
width: 100%;
padding: 0 5px;
height: 40px;
font-size: 16px;
border: none;
background: none;
outline: none;
}



.no-outlin:focus{
outline: none;
}

.txt_field label{
position: absolute;
top: 50%;
left: 5px;
color: #adadad;
transform: translateY(-50%);
font-size: 16px;
pointer-events: none;
transition: .7s;
border: none;
}

.txt_field span::before{
content: '';
position: absolute;
top: 40px;
left: 0;
width: 0%;
height: 2px;
background: #2691d9;
transition: .7s;
}

.txt_field input:focus ~ label,
.txt_field input:valid ~ label {
top: -5px;
color: #2691d9;
}

.txt_field input:focus ~ span::before,
.txt_field input:valid ~ span::before {
width: 100%;
}

.pass {
margin: -5px 0 20px 5px;
color: #a6a6a6;
cursor: pointer;
}

.pass:hover {
text-decoration: underline;
}

input[type="submit"]{
width: 100%;
height: 50px;
border: 1px solid;
background: #2691d9;
border-radius: 25px;
font-size: 18px;
color: #e9f4fb;
font-weight: 700;
cursor: pointer;
outline: none;
}

input[type="submit"]:hover{
border-color: #2691d9;
transition: .5s;
}

.signup_link {
margin: 30px;
text-align: center;
font-size: 16px;
color: #666666;
}

.signup_link a{
color: #2691d9;
text-decoration: none;
}

.signup_link a:hover{
color: #2691d9;
text-decoration: underline;
}
<head>

</head>
<body class="Body">

<div class="center">
<h1> Login </h1>
<form method="post" class="Box">
<div class="txt_field">
<input  type="text" required>
<span></span>
<label>Username</label>
</div>
<div class="txt_field">
<input type="password" required>
<span></span>
<label>Password</label>
</div>
<div class="pass"> Forgotten Password? </div>
<input type="submit" value="Login">
<div class="signup_link">
Not a Member? <a class="nav-item-nav-link" routerLink="/register">Create an Account!</a>
</div>

</form>
</div>

点击此处查看sceenshot

您的CSS 中有一个拼写错误

将CSS中的txt-field更改为txt_field

这是您的代码:

.center {
position: fixed;
top: 40%;
left: 70%;
transform: translate(-50%, -50%);
width: 720px;
height: 350px;
background: linear-gradient(180deg, white, silver);
size: 100%;
border-style: solid;
border-color: black;
border-width: 1px;
}
.center h1 {
text-align: center;
padding: 0 0 20px 0;
border-bottom: 1px solid silver;
}
.center form {
padding: 0 40px;
}
form .txt_field {
position: relative;
border-bottom: 2px solid #adadad;
margin: 30px 0;
}
.txt_field input {
width: 100%;
padding: 0 5px;
height: 40px;
font-size: 16px;
border: none;
background: none;
outline: none;
}
.no-outlin:focus {
outline: none;
}
.txt_field label {
position: absolute;
top: 50%;
left: 5px;
color: #adadad;
transform: translateY(-50%);
font-size: 16px;
pointer-events: none;
transition: .7s;
border: none;
}
.txt_field span::before {
content: '';
position: absolute;
top: 40px;
left: 0;
width: 0%;
height: 2px;
background: #2691d9;
transition: .7s;
}
.txt_field input:focus~label,
.txt_field input:valid~label {
top: -5px;
color: #2691d9;
}
.txt_field input:focus~span::before,
.txt_field input:valid~span::before {
width: 100%;
}
.pass {
margin: -5px 0 20px 5px;
color: #a6a6a6;
cursor: pointer;
}
.pass:hover {
text-decoration: underline;
}
input[type="submit"] {
width: 100%;
height: 50px;
border: 1px solid;
background: #2691d9;
border-radius: 25px;
font-size: 18px;
color: #e9f4fb;
font-weight: 700;
cursor: pointer;
outline: none;
}
input[type="submit"]:hover {
border-color: #2691d9;
transition: .5s;
}
.signup_link {
margin: 30px;
text-align: center;
font-size: 16px;
color: #666666;
}
.signup_link a {
color: #2691d9;
text-decoration: none;
}
.signup_link a:hover {
color: #2691d9;
text-decoration: underline;
}
<head>
</head>
<body class="Body">
<div class="center">
<h1> Login </h1>
<form method="post" class="Box">
<div class="txt_field">
<input type="text" required>
<span></span>
<label>Username</label>
</div>
<div class="txt_field">
<input type="password" required>
<span></span>
<label>Password</label>
</div>
<div class="pass"> Forgotten Password? </div>
<input type="submit" value="Login">
<div class="signup_link">
Not a Member? <a class="nav-item-nav-link" routerLink="/register">Create an Account!</a>
</div>
</form>
</div>

目标是输入而非div

.center {
position: fixed;
top: 40%;
left: 70%;
transform: translate(-50%, -50%);
width: 720px;
height: 350px;
background: linear-gradient(180deg, white, silver);
size: 100%;
border-style: solid;
border-color: black;
border-width: 1px;
}
.center h1 {
text-align: center;
padding: 0 0 20px 0;
border-bottom: 1px solid silver;
}
.center form {
padding: 0 40px;
}
form .txt_field {
position: relative;
border-bottom: 2px solid #adadad;
margin: 30px 0;
}
.txt_field input:focus {
outline: none;
}
.no-outlin:focus {
outline: none;
}
.txt_field label {
position: absolute;
top: 50%;
left: 5px;
color: #adadad;
transform: translateY(-50%);
font-size: 16px;
pointer-events: none;
transition: .7s;
border: none;
}
.txt_field span::before {
content: '';
position: absolute;
top: 40px;
left: 0;
width: 0%;
height: 2px;
background: #2691d9;
transition: .7s;
}
.txt_field input:focus~label,
.txt_field input:valid~label {
top: -5px;
color: #2691d9;
}
.txt_field input:focus~span::before,
.txt_field input:valid~span::before {
width: 100%;
}
.pass {
margin: -5px 0 20px 5px;
color: #a6a6a6;
cursor: pointer;
}
.pass:hover {
text-decoration: underline;
}
input[type="submit"] {
width: 100%;
height: 50px;
border: 1px solid;
background: #2691d9;
border-radius: 25px;
font-size: 18px;
color: #e9f4fb;
font-weight: 700;
cursor: pointer;
outline: none;
}
input[type="submit"]:hover {
border-color: #2691d9;
transition: .5s;
}
.signup_link {
margin: 30px;
text-align: center;
font-size: 16px;
color: #666666;
}
.signup_link a {
color: #2691d9;
text-decoration: none;
}
.signup_link a:hover {
color: #2691d9;
text-decoration: underline;
}
<head>
</head>
<body class="Body">
<div class="center">
<h1> Login </h1>
<form method="post" class="Box">
<div class="txt_field">
<input type="text" required>
<span></span>
<label>Username</label>
</div>
<div class="txt_field">
<input type="password" required>
<span></span>
<label>Password</label>
</div>
<div class="pass"> Forgotten Password? </div>
<input type="submit" value="Login">
<div class="signup_link">
Not a Member? <a class="nav-item-nav-link" routerLink="/register">Create an Account!</a>
</div>
</form>
</div>

相关内容

  • 没有找到相关文章

最新更新