为什么我的输入表单的转换不起作用?
Why isn't transition for my input forms working?
我曾尝试将过渡添加到我的输入表单中,但它不起作用。我读过很多堆栈溢出的帖子,但它们对我没有用。有人说是因为input有display: none
,改了还是不行。我在使用 transition
时尝试更具体,但这没有用。所以我不确定如何解决这个问题。过渡适用于按钮,但不适用于输入表单。
https://codepen.io/i-am-programming/pen/gOmydqv
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:wght@200&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="styles.css" />
<title>Document</title>
</head>
<body>
<nav>
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Store</a>
<a href="#">Contact Us </a>
</nav>
<div class="container">
<h1 class="login">Log In</h1>
<input type="text" placeholder="Username" class="username info" />
<input type="password" placeholder="Password" class="pass info" />
<input type="button" class="button" value="Submit" />
</div>
<script src="app.js"></script>
</body>
</html>
* {
margin: 0;
padding: 0;
font-size: 25px;
font-family: "Montserrat", sans-serif;
}
body {
background: url("images/background.jpeg");
background-size: cover;
}
a {
text-decoration: none;
margin-right: 30px;
color: #fff;
background-color: rgba(0, 0, 0, 0.7);
padding: 8px;
transition: 0.3s ease;
}
nav {
margin-top: 20px;
display: flex;
flex-direction: row;
justify-content: flex-end;
}
a:hover {
color: black;
background-color: rgba(255, 255, 255, 0.7);
}
.container {
display: flex;
flex-direction: column;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 500px;
height: 450px;
background-color: rgba(0, 0, 0, 0.7);
align-items: center;
}
.login {
color: white;
margin-top: 50px;
font-size: 45px;
}
input {
outline: none;
padding: 5px;
transition: 0.3s;
}
input:hover {
width: 400px;
}
.username {
position: absolute;
top: 45%;
left: 50%;
transform: translate(-50%, -50%);
}
.pass {
position: absolute;
top: 65%;
left: 50%;
transform: translate(-50%, -50%);
}
.button {
width: 150px;
margin-top: 250px;
}
我觉得你在input
里面少了transition
属性,会是这样的:
input {
height: 30px;
width: 300px;
outline: none;
transition: all 0.5s ease;
}
input:hover {
width: 500px;
}
首先你的文本代码和link不一样。其次,您不能在显示上使用过渡,因为它不可设置动画。您可以使用不透明度和可见性而不是显示。如果我们提出问题..
您想在用户悬停时获得更大的输入位置吗?因此,在您的示例中,您的输入没有任何宽度,当您悬停它时,您希望获得过渡。为此,您需要向输入添加一个宽度值,以便它知道更改从哪里开始以及您最后想要什么。同时,您通过的时间是您过渡的时间属性。所以
input {
height: 30px;
width: 300px;
outline: none;
transition: 0.3s;
}
input:hover {
width: 400px;
}
它会知道当用户悬停在它上面时,它会在0.3秒内从300px增长到400px。而已。希望你能明白。
这是因为您没有指定输入的宽度
我曾尝试将过渡添加到我的输入表单中,但它不起作用。我读过很多堆栈溢出的帖子,但它们对我没有用。有人说是因为input有display: none
,改了还是不行。我在使用 transition
时尝试更具体,但这没有用。所以我不确定如何解决这个问题。过渡适用于按钮,但不适用于输入表单。
https://codepen.io/i-am-programming/pen/gOmydqv
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:wght@200&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="styles.css" />
<title>Document</title>
</head>
<body>
<nav>
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Store</a>
<a href="#">Contact Us </a>
</nav>
<div class="container">
<h1 class="login">Log In</h1>
<input type="text" placeholder="Username" class="username info" />
<input type="password" placeholder="Password" class="pass info" />
<input type="button" class="button" value="Submit" />
</div>
<script src="app.js"></script>
</body>
</html>
* {
margin: 0;
padding: 0;
font-size: 25px;
font-family: "Montserrat", sans-serif;
}
body {
background: url("images/background.jpeg");
background-size: cover;
}
a {
text-decoration: none;
margin-right: 30px;
color: #fff;
background-color: rgba(0, 0, 0, 0.7);
padding: 8px;
transition: 0.3s ease;
}
nav {
margin-top: 20px;
display: flex;
flex-direction: row;
justify-content: flex-end;
}
a:hover {
color: black;
background-color: rgba(255, 255, 255, 0.7);
}
.container {
display: flex;
flex-direction: column;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 500px;
height: 450px;
background-color: rgba(0, 0, 0, 0.7);
align-items: center;
}
.login {
color: white;
margin-top: 50px;
font-size: 45px;
}
input {
outline: none;
padding: 5px;
transition: 0.3s;
}
input:hover {
width: 400px;
}
.username {
position: absolute;
top: 45%;
left: 50%;
transform: translate(-50%, -50%);
}
.pass {
position: absolute;
top: 65%;
left: 50%;
transform: translate(-50%, -50%);
}
.button {
width: 150px;
margin-top: 250px;
}
我觉得你在input
里面少了transition
属性,会是这样的:
input {
height: 30px;
width: 300px;
outline: none;
transition: all 0.5s ease;
}
input:hover {
width: 500px;
}
首先你的文本代码和link不一样。其次,您不能在显示上使用过渡,因为它不可设置动画。您可以使用不透明度和可见性而不是显示。如果我们提出问题..
您想在用户悬停时获得更大的输入位置吗?因此,在您的示例中,您的输入没有任何宽度,当您悬停它时,您希望获得过渡。为此,您需要向输入添加一个宽度值,以便它知道更改从哪里开始以及您最后想要什么。同时,您通过的时间是您过渡的时间属性。所以
input {
height: 30px;
width: 300px;
outline: none;
transition: 0.3s;
}
input:hover {
width: 400px;
}
它会知道当用户悬停在它上面时,它会在0.3秒内从300px增长到400px。而已。希望你能明白。
这是因为您没有指定输入的宽度