在尝试像this这样的焦点时,我试图将标签移到输入字段上方。
但是在我的其他code中,它仅更改字体大小并且没有向上移动。我想念什么?
我对两者都使用相同的CSS代码:
CSS
input:focus + label > span {
font-size: 12px;
transform: translate3d(0, -80%, 0);
transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
}
答案 0 :(得分:0)
如果您定位标签中包含的跨度,则可以使用以下代码对其进行控制。
input + label > span {
position: relative;
display: block;
bottom: -1em
}
您的代码需要做很多工作,但是从这里开始:
body {
background-color: #f0f0f0;
}
form {
margin-left: 40%;
margin-top: 11%;
}
label {
font-family: monospace; 'Montserrat', sans-serif;
font-size: 19px;
margin-left: -26%;
z-index: -1;
/* border: 5px solid black;*/
}
.head {
margin-left: 43%;
margin-top: 5%;
font-size: 25px;
font-family: monospace;
}
form {
position: relative; }
.input-field {
display:block;
background: transparent;
border-width: 2px;
border-top: 0;
border-left: 0;
border-right: 0;
border: 0;
background: transparent;
outline: 0;
height: 23px;
border-color: black;
width: 130px;
z-index: 1;
margin-left: 0%;
}
/*input:focus {
transform: scale3d(1, 1, 1);
transition: width 5s;
transition-delay: 3s;
transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
z-index: -1;
background: green; /* ::after background *
} */
label::after {
content: '';
position: absolute;
top: 100%;
left: 0;
width: 30%;
height: 20%;
transition: transform 0.8s;
}
label::after {
z-index: -1;
background: green; /* ::after background */
transform: scale3d(1, 0.1, 1);
transform-origin: 0% 0%;
}
input:focus + label::after {
transform: scale3d(1, -2, 1);
transition-timing-function: linear;
}
input:focus + label > span {
font-size: 14px;
transform: translate3d(0, -200%, 0);
transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
}
input + label > span {
position: relative;
display: block;
bottom: -1em
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<title>Test</title>
</head>
<body>
<p class="head">Sign In</p>
<form>
<div class="username">
<input type="text" name="name" class="input-field" id="user"/> <!--input filed-->
<label for="user">
<span class="username">Username</span>
</label>
</div>
</form>
</body>
</html
答案 1 :(得分:0)
已过滤的代码。您可以使用此代码。这很好。
.object {
position: relative;
z-index: 1;
display: inline-block;
width: 300px; /* input field width */
}
.input {
position: relative;
display: block;
float: right;
width: 30%;
border: none;
background: black;
color: yellow; /* font color when typing */
font-family: monospace;
/* for box shadows to show on iOS */
}
.input:focus {
outline: none;
}
.label {
display: inline-block;
color: black; /* label font color */
font-size: 18px;
font-family: monospace;
}
.label-content {
position: relative;
display: block;
padding: .6em 0;
}
.input--jiro {
padding: 0.85em 0.5em;
width: 100%; /* input width when focus */
background: blue ; /* input background color */
opacity: 0;
transition: opacity 0.3s;
}
.label-content--jiro {
transition: transform 0.3s 0.3s;
}
.label--jiro {
position: absolute;
left: 0;
padding: 0 0.85em;
width: 120%; /* underline width */
height: 100%;
}
label::after {
content: '';
position: absolute;
top: 100%;
left: 0;
width: 80%;
height: 100%;
transition: transform .8s;
}
label::after {
z-index: -1;
background: green; /* ::after background */
transform: scale3d(1, 0.1, 1);
transform-origin: 0% 0%; /* 0% 50%; * for middle */
}
input:focus + label::after {
transform: scale3d(1, -1, 1);
transition-timing-function: linear;
}
input:focus + label > span {
font-size: 12px;
transform: translate3d(0, -80%, 0);
transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
}
<p class="head">Sign In</p>
<section>
<span class="object">
<input class="input input--jiro" type="text" id="input-10" /> <!-- input field -->
<label class="label label--jiro" for="input-10">
<span class="label-content label-content--jiro">Username</span> <!-- Label -->
</label>
</span>
</section>