-
Notifications
You must be signed in to change notification settings - Fork 0
/
tabelas-parte_3.html
executable file
·454 lines (437 loc) · 15.8 KB
/
tabelas-parte_3.html
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta name="keywords" content="HTML,CSS" />
<meta name="author" content="Alexandre Gomes de Lima" />
<link href='http://fonts.googleapis.com/css?family=Inconsolata:400,700' rel='stylesheet' type='text/css' />
<link rel="stylesheet" type="text/css" href="estilos/aulas.css" />
<title>IFRN/DIATINF/Design Web: tabelas - parte 3</title>
</head>
<body>
<div id="tudo">
<header id="cabecalho">
<img src="imagens/logo_ifrn.png" alt="IFRN" id="logoifrn" />
<h1 class="cabecalho">
Diretoria Acadêmica de Gestão e Tecnologia da Informação
</h1>
<h2 class="cabecalho">
Disciplina de Design Web e Arquitetura da Informação
</h2>
</header>
<article id="conteudo">
<section>
<h1>Tabelas - parte 3</h1>
<p>
Em aulas anteriores, vimos como definir tabelas em páginas HTML e também como realizar
a mesclagem de células. Nesta aula, vamos ver a aplicação de propriedades
CSS na estilização de tabelas e conhecer mais detalhes de marcação
de tabelas através dos elementos <span class="html">caption</span>,
<span class="html">thead</span>, <span class="html">tfoot</span> e
<span class="html">tbody</span>.
</p>
</section>
<section>
<h2>Estilização de tabelas</h2>
<p>
Vamos relembrar os elementos para marcação de tabelas vistos até aqui:
</p>
<ul>
<li><span class="html">table</span>: define uma tabela.</li>
<li><span class="html">tr</span>: define uma linha.</li>
<li><span class="html">td</span>: define uma célula de conteúdo.</li>
<li><span class="html">th</span>: define uma célula de caeçalho.</li>
</ul>
<p>A seguir, é apresentado um exemplo de uso destes elementos.</p>
<pre class="html">
<table>
<tr>
<th>Nação</th>
<th>População</th>
<th>IDH</th>
<th>PIB (milhões de U$$)</th>
<th>PIB per capita (U$$)</th>
<th>Gini</th>
</tr>
<tr>
<td>Brasil</td>
<td>190.755.799</td>
<td>0,718</td>
<td>2.569.471,00</td>
<td>12.789</td>
<td>51,9</td>
</tr>
<tr>
<td>Chile</td>
<td>17.423.214</td>
<td>0,819</td>
<td>248.411,00</td>
<td>14.278</td>
<td>50,3</td>
</tr>
<tr>
<td>EUA</td>
<td>315.791.284</td>
<td>0,956</td>
<td>15.094.025,00</td>
<td>48.387</td>
<td>47,7</td>
</tr>
<tr>
<td>Canadá</td>
<td>34.674.708</td>
<td>0,966</td>
<td>1.736.869,00</td>
<td>50.435</td>
<td>32,1</td>
</tr>
<tr>
<td>África do Sul</td>
<td>50.738.255</td>
<td>0,629</td>
<td>408.074,00</td>
<td>8.066</td>
<td>63,1</td>
</tr>
<tr>
<td>Argentina</td>
<td>40.117.096</td>
<td>0,811</td>
<td>435.200,00</td>
<td>10.639</td>
<td>45,8</td>
</tr>
</table>
</pre>
<img src="tabelas-parte_3/exemplo1.png"
alt="visualização do exemplo 1" />
<p>
Como pode ser visto na figura, a formatação padrão do navegador não é muito atraente.
Estilos CSS podem ser utilizados para melhorar a apresentação visual da tabela.
Vamos começar aplicando bordas ao elemento <span class="html">table</span>:
</p>
<pre class="html">
<b>table { border: solid 2px black; }</b>
</pre>
<img src="tabelas-parte_3/exemplo2.png" alt="visualização do exemplo 2" />
<p>
Como podemos ver pelo exemplo anterior, a propriedade <span class="html">border</span>
aplicada ao elemento <span class="html">table</span> estiliza apenas a borda ao
redor da tabela, não tendo qualquer efeito sobre as bordas das células. Vamos, então,
verificar qual é o resultado ao aplicar um estilo de borda ao elemento
<span class="html">td</span>:
</p>
<pre class="html">
table { border: solid 2px black; }
<strong>td { border: solid 1px black; }</strong>
</pre>
<img src="tabelas-parte_3/exemplo3.png"
alt="visualização do exemplo 3" />
<p>
Com a última alteração, podemos ver que quase todas as células receberam uma borda.
A exceção ficou por conta das células da primeira linha da tabela.
Este comportamento é explicado pelo uso de elementos <span class="html">th</span> na
linha, e portanto, as regras CSS definidas para o elemento <span class="html">td</span>
não foram aplicadas. Para aproveitar o estilo de borda já definido para o elemento
<span class="html">td</span>, basta acrescentar o elemento <span class="html">th</span>
ao seletor da regra CSS:
</p>
<pre class="html">
table { border: solid 2px black; }
td, <strong>th</strong> { border: solid 1px black; }
</pre>
<img src="tabelas-parte_3/exemplo4.png"
alt="visualização do exemplo 4" />
<p>
Ao analisar as últimas figuras, podemos ver que há um espaço entre as células da tabela
bem como entre as células e a borda da tabela.
A ocorrência deste espaço é controlada pela propriedade <span class="html">border-collapse</span>,
a qual suporta os valores <span class="html">collapse</span>, <span class="html">separate</span>
(valor padrão) e <span class="html">inherit</span>. Vamos utilizar esta propriedade para
remover este espaçamento:
</p>
<pre class="html">
table {
border: solid 2px black;
<strong>border-collapse: collapse;</strong>
}
td, th { border: solid 1px black; }
</pre>
<img src="tabelas-parte_3/exemplo5.png"
alt="visualização do exemplo 5" />
<p>
A propriedade <span class="html">padding</span> também é aplicável às células de uma tabela:
</p>
<pre class="html">
table {
border: solid 2px black;
border-collapse: collapse;
}
td, th {
border: solid 1px black;
<strong>padding: 2px 6px 2px 6px;</strong>
}
</pre>
<img src="tabelas-parte_3/exemplo6.png"
alt="visualização do exemplo 6" />
<p>
Além de bordas e espaçamento, a CSS também permite a estilização do
fundo de uma tabela. Neste caso, as propriedades de background
podem ser aplicadas aos elementos
<span class="html">table</span>, <span class="html">tr</span>,
<span class="html">td</span> e <span class="html">th</span>.
Vamos utilizar a propriedade <span class="html">background-color</span>
para destacar as células de cabeçalho:
</p>
<pre class="html">
table {
border: solid 2px black;
border-collapse: collapse;
}
td, th {
border: solid 1px black;
padding: 2px 6px 2px 6px;
}
<strong>th {
background-color: pink;
}</strong>
</pre>
<img src="tabelas-parte_3/exemplo7.png"
alt="visualização do exemplo 7" />
<p>
Para a formatação do texto, vamos começar pela fonte utilizada na tabela:
</p>
<pre class="html">
table {
border: solid 2px black;
border-collapse: collapse;
<strong>font-family: arial;
font-size: 85%;</strong>
}
td, th {
border: solid 1px black;
padding: 2px 6px 2px 6px;
}
th {
background-color: pink;
}
</pre>
<p>
Desta forma, os elementos <span class="html">tr</span>, <span class="html">td</span>
e <span class="html">th</span> herdarão as propriedades de fonte definidas para
<span class="html">table</span>.
</p>
<p>
Agora vamos definir alinhamento de texto à esquerda para a primeira coluna e
alinhamento de texto à direita para as demais colunas. As células de cabeçalho permancerão
com alinhamento padrão:
</p>
<pre class="html">
table {
border: solid 2px black;
border-collapse: collapse;
font-family: arial;
font-size: 85%;
}
td, th {
border: solid 1px black;
padding: 2px 6px 2px 6px;
}
th {
background-color: pink;
}
<strong>td {
text-align: right;
}
td:first-child {
text-align: left;
}</strong>
</pre>
<img src="tabelas-parte_3/exemplo8.png"
alt="visualização do exemplo 8" />
<p>
A propriedade <span class="html">vertical-align</span> permite, através dos valores
<span class="html">top</span>, <span class="html">middle</span> e
<span class="html">bottom</span>, definir a posição vertical do conteúdo
de uma tabela. Veja o exemplo a seguir:
</p>
<pre class="html">
table { border-collapse: collapse; }
td {
border: solid 1px black;
padding: 4px;
<b>vertical-align: top;</b>
}
<table>
<tr>
<td rowspan="3">Região Sul</td>
<td>RS</td>
</tr>
<tr>
<td>SC</td>
</tr>
<tr>
<td>PR</td>
</tr>
</table>
</pre>
<img src="tabelas-parte_3/exemplo9.png"
alt="visualização do exemplo 9" />
</section>
<section>
<h2>Mais elementos de tabela</h2>
<p>
O elemento <span class="html">caption</span> permite a definição de títulos de tabelas.
Por padrão, esse elemento é renderizado com alinhamento centralizado e acima da tabela,
mas é possível utilizar propridades CSS para alterar essa configuração.
</p>
<p>
Os elementos <span class="html">thead</span> e <span class="html">tfoot</span> são
utilizados para agrupar, respectivamente, linhas de cabeçalho e linhas de rodapé
de uma tabela. Estes elementos são úteis quando trabalhamos com tabelas extensas pois possibilitam
que o navegador ofereça rolagem apenas no corpo da tabela enquanto mantém o cabeçalho e
o rodapé visíveis. No caso de impressão, este elementos fazem com que o cabeçalho e o rodapé da tabela
sejam impressos em cada uma das páginas. Além disso, tais elementos deixam a marcação com uma
semântica mais rica e ainda podem facilitar a estilização da tabela.
</p>
<p>
Caso <span class="html">thead</span> e <span class="html">tfoot</span> sejam utilizados,
as linhas de conteúdo da tabela deverão estar contidas no elemento <span class="html">tbody</span>.
</p>
<p>
No próximo exemplo é demonstrado o uso destes elementos. Repare que o elemento <span class="html">tfoot</span>
deve ser declarado após <span class="html">thead</span> e antes de <span class="html">tbody</span>.
</p>
<pre class="html">
table{
border: solid 2px black;
}
.valor{
text-align: right;
}
td, th {
border: solid 1px black;
padding: 2px 4px 2px 4px;
}
thead{
background-color: silver;
}
tfoot{
background-color: pink;
}
tfoot th:first-child{
text-align: left;
}
<table>
<b><caption>Brasil - PIB por região (2011)</caption>
<thead>
<tr>
<th>Região</th>
<th>PIB (milhões de R$)</th>
</tr>
</thead>
<tfoot>
<tr>
<th>TOTAL</th>
<th class="valor">4.143.013</th>
</tr>
</tfoot></b>
<tbody>
<tr>
<td>Sudeste</td>
<td class="valor">2.295.690</td>
</tr>
<tr>
<td>Sul</td>
<td class="valor">672.049</td>
</tr>
<tr>
<td>Nordeste</td>
<td class="valor">555.325</td>
</tr>
<tr>
<td>Centro-oeste</td>
<td class="valor">396.411</td>
</tr>
<tr>
<td>Norte</td>
<td class="valor">223.538</td>
</tr>
</tbody>
</table>
</pre>
<img src="tabelas-parte_3/exemplo10.png"
alt="visualização do exemplo 10" />
</section>
<section class="exercicios">
<h2>Exercícios</h2>
<p>
1) Crie e estilize cada uma das tabelas apresentadas nas figuras a seguir:
</p>
<p style="padding-left: 2em">
a) <img src="tabelas-parte_3/exercicio1a.png" alt="tabela do exercício 1.a" style="vertical-align: top" />
</p>
<p style="padding-left: 2em">
b) <img src="tabelas-parte_3/exercicio1b.png" alt="tabela do exercício 1.a" style="vertical-align: top" />
</p>
<p>
2) Dado o código HTML de tabela abaixo, aplique estilos para deixar
a tabela com o visual apresentado na figura seguinte. Faça o que se
pede sem alterar a marcação HTML da tabela. As imagens ecnontram-se
no arquivo <a href="tabelas-parte_3/icones.zip">icones.zip</a>.
</p>
<pre class="html">
<table>
<caption>Viação Alfa</caption>
<thead>
<tr>
<th></th>
<th class="hora">Hora de saída</th>
<th class="hora">Hora de chegada</th>
<th class="classe">Classe do ônibus</th>
<th class="tarifa">Tarifa</th>
</tr>
<tfoot>
<tr>
<td colspan="5">Vigência: 02/04/2014 a 15/06/2014</td>
</tr>
</tfoot>
<tbody>
<tr>
<th>Cidade A</th>
<td>06:45</td>
<td>14:30</td>
<td>Convencional</td>
<td>80,00</td>
</tr>
<tr>
<th>Cidade B</th>
<td>12:30</td>
<td>21:00</td>
<td>Convencional</td>
<td>100,00</td>
</tr>
<tr>
<th>Cidade C</th>
<td>19:00</td>
<td>06:00</td>
<td>Leito</td>
<td>150,00</td>
</tr>
</tbody>
</thead>
</table>
</pre>
<img src="tabelas-parte_3/exercicio2.png"
alt="resultado final da tabela" />
</section>
<h2 class="referencias">Referências</h2>
<ul>
<li class="referencia">
SILVA, Maurício Samy. <em class="referencia">Construindo sites com CSS e (X)HTML: sites controlados
por folhas de estilo em cascata</em>. São Paulo: Novatec, 2008.
</li>
</ul>
</article>
</div>
</body>
</html>