-
Notifications
You must be signed in to change notification settings - Fork 0
/
css-parte_2.html
executable file
·336 lines (311 loc) · 15.1 KB
/
css-parte_2.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
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta name="keywords" content="HTML,CSS" />
<meta name="author" content="Alexandre Gomes de Lima" />
<meta charset="UTF-8">
<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: CSS parte 2</title>
</head>
<body>
<div id="tudo">
<header id="cabecalho">
<img src="imagens/logo_ifrn.png" alt="Logotipo do 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">
<h1>Introdução a CSS - parte 2</h1>
<p>
Na aula passada fomos apresentados às folhas de estilos e vimos três formas de como aplicá-las
nas páginas web (inline, internas e externas). Nesta aula iremos conhecer mais informações a
respeito de como os estilos são aplicados aos elementos HTML, como também vamos conhecer
melhor os seletores CSS.
</p>
<h2>Efeito cascata e herança</h2>
<p>
Já sabemos que o autor de uma página web pode criar estilos de formatação para serem aplicados
aos elementos HTML. No entanto, ao visualizarmos uma página no navegador, todos os
seus elementos recebem uma formatação mesmo que o autor não tenha definido quaisquer estilos.
Por exemplo, veja código HTML a seguir e a sua respectiva visualização em um navegador:
</p>
<pre class="html">
<html>
<head>
<title>Exemplo 1</title>
</head>
<body>
<h1>Lorem ipsum</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat
nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
officia deserunt mollit anim id est laborum.
</p>
</body>
</html>
</pre>
<img src="css-parte_2/exemplo01.png" alt="Visualização de página sem estilos" />
<p>
Isto acontece porque o navegador possui uma folha de estilo própria que ele utiliza para aplicar
uma formatação padrão. No entanto, apenas os elementos que não possuem estilos definidos pelo autor
da página receberão a formatação padrão do navegador. Ou seja, <strong>os estilos definidos pelo
autor possuem prioridade em relação aos estilos do navegador</strong>.
</p>
<p>
Entre os estilos definidos pelo autor, é adotada a seguinte ordem de prioridade:
</p>
<ul class="semmarcador">
<li>1º estilos inline.</li>
<li>2º folhas de estilo internas.</li>
<li>3º folhas de estilo externas.</li>
</ul>
<p>
Esta ordem significa que os estilos inline possuem prioridade sobre as outras
formas de estilo e que os estilos internos precedem os estilos externos.
Em situações de conflito, o estilo a ser adotado será o de maior prioridade.
</p>
<p>
Vamos observar a precedência de estilos na prática. No arquivo
<a href="css-parte_2/exemplo01.html">exemplo01.html</a>, adicione os estilos
presentes no código abaixo. Em seguida, abra o arquivo no navegador
e repare o prevalecimento do estilo inline.
</p>
<pre class="html">
<html>
<head>
<title>Exemplo 1</title>
<b><style type="text/css">
p { color: blue }
</style></b>
</head>
<body>
<h1>Lorem ipsum</h1>
<p <b>style="color: green"</b>>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat
nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
officia deserunt mollit anim id est laborum.
</p>
</body>
</html>
</pre>
<p>
O aninhamento das tags estabelece um relacionamento do tipo pai e filho (hieraquia) entre os
elementos HTML. Assim, no exemplo anterior <span class="html">html</span> é pai de
<span class="html">body</span> e ancestral de <span class="html">p</span>. Já a tag
<span class="html">body</span> é filha (e também descendente) de <span class="html">html</span>
e pai (e também ancestral) de <span class="html">p</span>. A partir dessa hierarquia surge
o conceito de herança, fazendo com que os elementos filhos aproveitem os estilos de seus
ancestrais. Os estilos herdados possuem prioridade menor do que os estilos definidos para
o próprio elemento.
</p>
<p>
Vamos verificar esse efeito na prática: em <a href="css-parte_2/exemplo01.html">exemplo01.html</a>,
adicione o estilo <span class="html">body { color: red }</span>. Recarregue a página e
observe que o texto em <span class="html">h1</span> foi formatado com a cor vermelha,
enquanto que o texto em <span class="html">p</span> continuou verde, prevalecendo
o estilo do elemento sobre o estilo herdado.
</p>
<img src="css-parte_2/heranca.png" alt="Visualização de estilo herdado e estilo inline" />
<p>
Vale ainda lembrar que somente algumas propriedades, tais como <span class="html">color</span> e
<span class="html">font-family</span>, são herdadas.
</p>
<p>
Esta lógica de propagação de estilos é denominada efeito cascata. Daí, a
presença do termo <em>cascade</em> na sigla CSS.
</p>
<h2>Seletores</h2>
<p>
Regras CSS formam as folhas de estilo. Uma regra CSS é formada por um conjunto de seletores e
uma ou mais propriedades CSS com seus respectivos valores. Por exemplo, no seguinte código
<span class="html">p</span> é o seletor, <span class="html">color</span> é a propriedade
CSS e <span class="html">blue</span> é o valor desta propriedade.
</p>
<pre class="html">
p { color: blue }
</pre>
<p>
O seletor tem como função especificar os elementos HTML que serão estilizados de acordo com
a regra CSS. No exemplo anterior, o seletor indica que todas as tags <span class="html">p</span>
serão estilizadas com cor de fonte azul.
</p>
<p>
Uma regra CSS pode conter múltiplos seletores. Vírgulas são utilizadas para separar os seletores.
O próximo exemplo indica que todas as tags <span class="html">p</span>,
<span class="html">h1</span> e <span class="html">code</span> serão estilizadas com cor de fonte azul.
</p>
<pre class="html">
p, h1, code { color: blue }
</pre>
<p>
Um tipo de seletor bastante poderoso é o seletor de classe. Uma classe representa um grupo de
elementos HTML ligados pelo estilo. A classe de um elemento HTML é definida pelo atributo
<span class="html">class</span>. Quando definimos uma regra CSS com seletor de classe, os
estilos desta regra serão aplicados a todos os elementos HTML marcados com a classe indicada
no seletor.
</p>
<p>
No exemplo a seguir, o cabeçalho e o primeiro parágrafo foram marcados com a classe
<span class="html">xx</span>, o segundo parágrafo foi marcado com a classe
<span class="html">yy</span> e há uma regra CSS para cada classe.
A figura mostra que cada elemento recebeu um estilo de acordo com sua classe.
Note que nomes de classes devem ser precedidos com um ponto ao serem referenciados por
seletores CSS.
</p>
<pre class="html">
<html>
<head>
<style type="text/css">
<b>.xx</b> {
font-family: serif;
background-color: #66CCFF;
}
<b>.yy</b> {
font-family: sans-serif;
background-color: #99FF66;
}
</style>
</head>
<body>
<h1 <b>class="xx"</b>>Cabeçalho</h1>
<p <b>class="xx"</b>>Parágrafo classe xx</p>
<p <b>class="yy"</b>>Parágrafo classe yy</p>
</body>
</html>
</pre>
<img src="css-parte_2/exemplo_classes_01.png" alt="Visualização do exemplo com classes" />
<p>
Também é possível definir regras baseadas no elemento HTML e na classe. No exemplo a seguir,
a regra <span class="html">p.xx</span> será aplicada apenas aos elementos <span class="html">p</span>
que estejam marcados com a classe <span class="html">xx</span>.
</p>
<pre class="html">
<html>
<head>
<style type="text/css">
p {
font-family: serif;
background-color: #66CCFF;
}
<b>p.xx</b> {
font-family: sans-serif;
background-color: #99FF66;
}
</style>
</head>
<body>
<p>Parágrafo sem classe</p>
<p class="xx">Parágrafo classe xx</p>
</body>
</html>
</pre>
<img src="css-parte_2/exemplo_classes_02.png" alt="Visualização do exemplo com seletor baseado em elemento e classe" />
<p>
Podemos utilizar o atributo <span class="html">id</span> para definir um identificador
a uma tag específica. Este identificador deve ser único no documento HTML. Seletores CSS
podem ser baseados em <span class="html">id</span>, bastando apenas preceder o identificador com o caractere
<strong>#</strong>.
</p>
<pre class="html">
<html>
<head>
<style type="text/css">
p {
font-family: serif;
background-color: cyan;
}
<b>#segundo</b> {
font-family: sans-serif;
background-color: pink;
font-size: 18pt;
}
</style>
</head>
<body>
<p>Primeiro parágrafo</p>
<p <b>id="segundo"</b>>Segundo parágrafo</p>
<p>Terceiro parágrafo</p>
</body>
</html>
</pre>
<img src="css-parte_2/exemplo_classes_03.png" alt="Visualização do exemplo com seletor baseado em id" />
<p>
Note que o efeito cascata prioriza os estilos mais específicos. Assim, seletores baseados em
<span class="html">id</span> possuem
prioridade sobre os seletores baseados em classes. Estes, por sua vez, são mais específicos que os
seletores baseados em tags.
</p>
<h2>Exercícios</h2>
<p>
1) Aplique estilos na página <a href="css-parte_2/exercicio01.html">exercicio01.html</a>
para deixá-la semelhante à figura abaixo.
Use estilos baseados em classe ou em <span class="html">id</span> para aplicar formatação
específica a cada parágrafo.
</p>
<img src="css-parte_2/exercicio01.png" alt="Resultado final" />
<p>
2) A partir do código HTML abaixo, responda:
</p>
<ol class="opcoes_exercicio">
<li>Qual será cor do texto no parágrafo sobre a balaiada?</li>
<li>Qual será cor do texto no parágrafo sobre a sabinada?</li>
<li>Qual será cor do texto no parágrafo sobre a guerra dos farrapos?</li>
<li>Qual será cor do texto no parágrafo sobre a cabanagem?</li>
<li>Qual será cor do texto no parágrafo com a fonte das informações?</li>
</ol>
<pre class="html">
<html>
<head>
<style type="text/css">
body { color: red }
p.yyy { color: blue }
#xxx { color: green }
</style>
</head>
<body>
<p>Balaiada foi uma revolta ocorrida no Maranhão entre os anos de 1838 e 1840.</p>
<p>
Sabinada foi uma revolta autonomista à época do Brasil Império. Ocorreu entre 6 de
novembro de 1837 e 16 de março de 1838, na então Província da Bahia.
</p>
<p class="yyy">
Guerra dos Farrapos ou Revolução Farroupilha são os nomes pelos quais ficou conhecida
a revolução ou guerra regional, de caráter republicano, contra o governo imperial do
Brasil, na então província de São Pedro do Rio Grande do Sul, e que resultou na
declaração de independência da província como estado republicano, dando origem à
República Rio-Grandense. Estendeu-se de 20 de setembro de 1835 a 1 de março de 1845.
</p>
<p id="xxx">
Cabanagem foi uma revolta social ocorrida no Império do Brasil, na então província
do Grão-Pará, estendendo-se de janeiro de 1835 a 1840, durante o período regencial
brasileiro. Marcado por um cenário de pobreza extrema, fome e doenças, o conflito existiu
muito devido à irrelevância política à qual a província foi relegada após a Independência
do Brasil. Dado o seu saldo de mortos exorbitante e a chacina de povos promovida pela
coroa, a Cabanagem é um dos maiores conflitos já ocorridos na história do país.
</p>
<p style="color: black">Fonte: Wikipedia</p>
</body>
</html>
</pre>
<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>