File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ 1 . 使用HTML、CSS写好一个输入框
2
+
3
+ 如何做到输入框无无文字时和输入文字时一致对齐?
4
+ chrome 浏览器的输入框光标、输入文字、占位符有以下规则:
5
+ - 无文字输入时,以行高为准;
6
+ - 有文字输入时,以文字大小为准;
7
+ - 占位符以行高为准。
8
+
9
+ 那么如何写好一个输入框:
10
+ 1 . 在书写输入框的时候,如果要增加光标高度,那么最可行的做法是增加文字的大小;
11
+ 2 . 输入框的剩余空白使用内边距填充;
12
+ 3 . 不要为输入框设置行高,因为浏览器默认会设置行高就会使占位符和输入光标、文字都居中;
13
+ 4 . 不要为输入框设置高度,因为已经使用了内边距撑开了,并且现在大多数 css 库都直接使用边框盒模型。
14
+
15
+ ```
16
+ <!DOCTYPE html>
17
+ <style>
18
+ body{
19
+ line-height: 20px;
20
+ }
21
+
22
+ #input1{
23
+ font-size: 40px;
24
+ padding: 10px;
25
+ line-height: normal;
26
+ }
27
+ </style>
28
+ <body>
29
+ <input type="text" id="input1" placeholder="input">
30
+ </body>
31
+ ```
32
+
33
+ demo: <http://codepen.io/paddingme/pen/cJGhl>
34
+
35
+ 相关链接:<http://qianduanblog.com/post/css-learning-21-using-html-css-write-an-input-box.html>
You can’t perform that action at this time.
0 commit comments