CSS中的::placeholder


本文作者: jsweibo

本文链接: https://jsweibo.github.io/2019/10/22/CSS%E4%B8%AD%E7%9A%84-placeholder/

摘要

本文主要讲述了:

  1. 作用

正文

作用

修改<input><textarea>的 placeholder 的样式

示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<input type="text" placeholder="placeholder" />
<textarea placeholder="placeholder"></textarea>
<style>
::placeholder {
color: #f00;
opacity: 0.5;
font-weight: bold;
font-size: 18px;
font-style: italic;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
</style>
</body>
</html>

示例:

注意:无法使用 CSS 的选择器列表

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<input type="text" placeholder="placeholder" />
<textarea placeholder="placeholder"></textarea>
<style>
::-moz-placeholder {
color: #f00;
opacity: 0.5;
font-weight: bold;
font-size: 18px;
font-style: italic;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
::-webkit-input-placeholder {
color: #f00;
opacity: 0.5;
font-weight: bold;
font-size: 18px;
font-style: italic;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
::placeholder {
color: #f00;
opacity: 0.5;
font-weight: bold;
font-size: 18px;
font-style: italic;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
</style>
</body>
</html>

参考资料

本文作者: jsweibo

本文链接: https://jsweibo.github.io/2019/10/22/CSS%E4%B8%AD%E7%9A%84-placeholder/


本文对你有帮助?请支持我


支付宝
微信