7. La propiedad display

Versión para imprimir.

En esta lección se presenta el concepto de polimorfismo.

A. El elemento div

Ejemplo

Salida

Ábrelo en otra pestaña.

Revísalo en gilpgedit.

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>div</title>
8 <style>
9 div {
10 color: chocolate;
11 }
12 </style>
13</head>
14<body>
15 <div>Un div simple.</div>
16 <div>Otro div simple.</div>
17 <p>Un párrafo simple.</p>
18 <p>Otro párrafo simple.</p>
19</body>
20</html>

Solo para los más rudos

B. El elemento span

Ejemplo

Salida

Ábrelo en otra pestaña.

Revísalo en gilpgedit.

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>span</title>
8 <style>
9 span {
10 color: magenta;
11 }
12 </style>
13</head>
14<body>
15 <p>
16 Hola,
17 <span>este es un span.</span>
18 Más texto
19 <span>otro span.</span>
20 </p>
21 <p>Otro párrafo simple.</p>
22</body>
23</html>

Solo para los más rudos

C. La propiedad display

D. El valor none

Ejemplo

Salida

Ábrelo en otra pestaña.

Revísalo en gilpgedit.

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>inline</title>
8 <style>
9 div {
10 display: none
11 }
12 </style>
13</head>
14<body>
15 <p>Ahora me ves.</p>
16 <div>Ahora no me ves.</div>
17</body>
18</html>

E. El valor inline

Ejemplo

Salida

Ábrelo en otra pestaña.

Revísalo en gilpgedit.

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>inline</title>
8 <style>
9 p {
10 display: inline;
11 color: olive
12 }
13 </style>
14</head>
15<body>
16 <div>
17 El texto es inline.
18 El texto es inline.
19 El texto es inline.
20 El texto es inline.
21 El texto es inline.
22 <span>El span es inline.</span>
23 <p>
24 Este párrafo es forzado a ser
25 inline.
26 </p>
27 <em>
28 Esto es texto con énfasis.
29 </em>
30 <strong>
31 Esto es texto con énfasis
32 fuerte.
33 </strong>
34 Más texto.
35 Más texto.
36 Más texto.
37 Más texto.
38 </div>
39</body>
40</html>

F. El valor block

Ejemplo

Salida

Ábrelo en otra pestaña.

Revísalo en gilpgedit.

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>block</title>
8 <style>
9 div {
10 background-color: yellow;
11 }
12 </style>
13</head>
14<body>
15 <h1>block</h1>
16 <p>
17 En este ejemplo, body solo
18 tiene elementos de bloque.
19 </p>
20 <p>
21 Este párrafo solo tiene contenido
22 inline e inline-block.
23 <em>Un énfasis inline.</em>
24 <button>
25 Un botón inline-block,
26 inline-block, inline-block
27 </button>
28 <span>
29 Un span inline, inline, inline,
30 inline.
31 </span>
32 </p>
33 <div>
34 Este div tiene contenido
35 mezclado.
36 <em>
37 Este es un énfasis inline.
38 </em>
39 <strong>
40 Este es un strong inline.
41 </strong>
42 <button>
43 Este es un botón inline-block
44 </button>
45 <p>
46 Este párrafo solo contiene
47 inline e inline-block.
48 <em>Un énfasis inline.</em>
49 <button>
50 Un botón inline-block
51 </button>
52 <span>Un span inline.</span>
53 </p>
54 </div>
55</body>
56</html>

G. El valor inline-block

Ejemplo

Salida

Ábrelo en otra pestaña.

Revísalo en gilpgedit.

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>inline-block</title>
8 <style>
9 span {
10 display: inline-block;
11 background-color: yellow;
12 }
13 </style>
14</head>
15<body>
16 <p>
17 Texto, texto, texto
18 <span>
19 Este es un span forzado a ser
20 inline-block, inline-block,
21 inline-block, inline-block.
22 </span>
23 <button>
24 Este es un botón inline-block,
25 inline-block, inline-block.
26 </button>
27 </p>
28</body>
29</html>

H. Resumen