:focus
Seleciona al elemento que en el momento actual reciba el control del teclado, estado que también se conoce como foco.
En cualquier momento, solo un componente gráfico tiene el foco.
1 | <!DOCTYPE html> |
2 | <html lang="es"> |
3 | <head> |
4 | <meta charset="UTF-8"> |
5 | <meta name="viewport" |
6 | content="width=device-width"> |
7 | <title>Selector :focus</title> |
8 | <style> |
9 | :focus { |
10 | color: red; |
11 | } |
12 | |
13 | input:focus { |
14 | background-color: yellow; |
15 | } |
16 | |
17 | textarea, |
18 | input { |
19 | display: block; |
20 | } |
21 | </style> |
22 | </head> |
23 | <body> |
24 | <h1>Selector :focus</h1> |
25 | <p> |
26 | <label> |
27 | Nombre |
28 | <input> |
29 | </label> |
30 | </p> |
31 | <p> |
32 | <label> |
33 | Relato |
34 | <textarea></textarea> |
35 | </label> |
36 | </p> |
37 | <p> |
38 | <span>Intenta teclear</span> |
39 | </p> |
40 | </body> |
41 | </html> |