0%

CSS创建简单的Material Design风格输入框。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style>
.input-fill:placeholder-shown::placeholder{color: transparent}
.input-fill-x{position: relative; margin:50px}
.input-fill{padding:5px}
.input-lable{
position: absolute;
left: 5px;
top: 3px;
pointer-events: none;
}
.input-fill:not(:placeholder-shown) ~ .input-label, .input-fill:focus ~ .input-lable{transform: scale(0.75) translate(0, -20px); background: #FFF; padding: 2px 4px}
</style>
</head>
<body>
<div class="input-fill-x">
<input class="input-fill" placeholder="Email">
<lable class="input-lable">Email</lable>
</div>
</body>
</html>