Top Banner
2009.03.04 HTML/XHTML <title>HTML/XHTML</title> <html> <head> </head> <body> </body> </html>
49

HTML - How To

Jan 13, 2015

Download

Technology

SAPO Sessions

Recap, best practices e forgotten tags.

Consolidação de conhecimentos de HTML, HTML vs. XHTML e mais algumas coisas que ainda não sabiam.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: HTML - How To

2009.03.04 HTML/XHTML

<title>HTML/XHTML</title>

<html>

<head>

</head>

<body>

</body>

</html>

Page 2: HTML - How To

2009.03.04 HTML/XHTML

André Torgal – Lisboa, Portugal - 2009-03-04

<html>

<head>

<title>HTML</title>

<meta name=”author”

content=”André Torgal”><meta name="geo.placename"

content="Lisboa, Portugal" /><meta name="DC.Date.Created"

content="2009-03-04">...

</head>

<body>

...

Page 3: HTML - How To

2009.03.04 HTML/XHTML

HOW-TO

XHTMLHTML

FAIL

COOL

Page 4: HTML - How To

2009.03.04 HTML/XHTML

HTML::State Of The Art

Estrutura

Semântica

Conteúdo

Usabilidade

Acessibilidade

SEO

...

Declarações

#referências

<estrutura><semântica>

... Contéudo

...</semântica>

</estrutura>

Page 5: HTML - How To

2009.03.04 HTML/XHTML

HTML::Apenas HTML

Estrutura

Semântica

Conteúdo

Declarações

#referências

<estrutura><semântica>

... Contéudo

...</semântica>

</estrutura>

Page 6: HTML - How To

2009.03.04 HTML/XHTML

XHTML1.0

STRICT2000

HTML XHTML

1986 1998

HTML 4.0.1

STRICT1999

SGML XML

Page 7: HTML - How To

2009.03.04 HTML/XHTML

Declarações

#referências

<estrutura><semântica>

... Conteúdo

...</semântica>

</estrutura>

COMPONENTES MARKUP

ELEMENT TYPE

TAG

ATTRIBUTE / VALUE

ELEMENT

CONTENT MODEL

DOCUMENT STRUCTURE

DECLARATIONS

COMMENTS

Page 8: HTML - How To

2009.03.04 HTML/XHTML

MARKUP

Processo de “marcar” o conteúdo com TAGS

Conjunto de TAGS de um documento.

“Ah e tal, é preciso meter aí um <BR />

“Ah e tal, é preciso mexer no markup”

Page 9: HTML - How To

2009.03.04 HTML/XHTML

ELEMENT TYPES / TAGS

Cada ELEMENT TYPE tem o seu TAG

Cada elemento é definido por um parOPENING TAG + CLOSING TAG

<tag>...conteúdo...

</tag>

Page 10: HTML - How To

2009.03.04 HTML/XHTML

HTML

Alguns ELEMENT TYPE podem dispensar CLOSING-TAG

(mas não é aconselhável)

<h1>Carpe Diem!<p>Lorem ipsum dolor sit amet.<p>Et pluribus unum.

ELEMENT TYPES / TAGS

Page 11: HTML - How To

2009.03.04 HTML/XHTML

XHTML

Todos os ELEMENT têm que abrir/fecharseja qual fôr o seu ELEMENT TYPE

(regra “well-formed” do XML)

ELEMENT TYPES / TAGS

<h1>Carpe Diem!</h1><p>Lorem ipsum dolor sit amet.</p><p>Et pluribus unum.</p>

Page 12: HTML - How To

2009.03.04 HTML/XHTML

HTML

Alguns ELEMENT TYPE não têm CLOSING-TAGporque nunca têm conteúdo

<br><hr><img src= “/media/logo.png”>

ELEMENT TYPES / TAGS

Page 13: HTML - How To

2009.03.04 HTML/XHTML

XHTML

Nos elementos sem conteúdo omite-se o CLOSING-TAG e dizem-se AUTO-CLOSING

(só se “deve” aplicar a elementos que não têm conteúdo por natureza... porquê?)

<link type=“text/css” href=“/style/x.css” /><br /> <img src= “/media/logo.png” /><div />

ELEMENT TYPES / TAGS

Page 14: HTML - How To

2009.03.04 HTML/XHTML

ATTRIBUTES

Cada ELEMENT TYPE tem um conjunto de ATTRIBUTES possíveis

Ex: id, class

<tag id=“foo” class=“bar”>...conteúdo...

</tag>

Page 15: HTML - How To

2009.03.04 HTML/XHTML

HTML

Os TAGS ou ATTRIBUTES não são case-sensitive

(mas é aconselhável só usar minúsculas)

TAGS / ATTRIBUTES

<Tag ID=“foo” class=“bar”>...conteúdo...

</Tag>

Page 16: HTML - How To

2009.03.04 HTML/XHTML

XHTML

Os TAGS e ATTRIBUTES são case-sensitive

(usar minúsculas sempre!)

TAGS / ATTRIBUTES

<tag id=“foo” class=“bar”>...conteúdo...

</tag>

Page 17: HTML - How To

2009.03.04 HTML/XHTML

HTML

Alguns ATTRIBUTES de alguns TAGSpodem ser minimizados

TAGS / ATTRIBUTES

<option value=“pt” selected>Portugal

</option>

Page 18: HTML - How To

2009.03.04 HTML/XHTML

XHTML

Nenhum ATTRIBUTE pode ser minimizado

(usa-se o valor igual ao nome do atributo)

TAGS / ATTRIBUTES

<option value=“pt” selected=“selected”>Portugal

</option>

Page 19: HTML - How To

2009.03.04 HTML/XHTML

CONTENT MODEL

O elemento principal do conteúdo é o BODY

Dentro deste, cada ELEMENT TYPE é:

BLOCK LEVEL INLINE LEVEL

<body>...conteúdo...

</body>

Page 20: HTML - How To

2009.03.04 HTML/XHTML

BLOCK LEVEL

DIV

H1 .. H6

P

BLOCKQUOTE

UL, OL, DL

ADDRESS

TABLE

<h1>welcome</h1><p>foo</p><div>bar</div>

welcome

foo

bar

Page 21: HTML - How To

2009.03.04 HTML/XHTML

INLINE LEVEL

SPAN

A

STRONG, EM

IMG

CITE, CODE

INPUT

SELECT

<p>Lorem Ipsum    <span>alfa</span>    <em>beta</em>.</p>

Lorem Ipsum alfa beta.

Page 22: HTML - How To

2009.03.04 HTML/XHTML

CONTAINER / CONTENTS

Cada ELEMENT pode conter + ELEMENTS...

<tag id=“foo” class=“bar”><tag>    <tag>        ...conteúdo...    </tag></tag>

</tag>

Page 23: HTML - How To

2009.03.04 HTML/XHTML

CONTAINER / CONTENT MODEL

...mas apenas de terminados ELEMENT TYPE

- BODY só pode conter BLOCK LEVEL

- INLINE LEVEL não pode conter BLOCK

- ... e várias outras regras específicas

<span><p>...</p>

</span>

<p><p>....</p>

</p>✗  ✗ 

Page 24: HTML - How To

2009.03.04 HTML/XHTML

MARKUP (BÁSICO)

Texto

H1.6 P, SPAN, EM, STRONG, BLOCKQUOTE, ABBR

Listas/Items

UL, OL, LI, DL, DT, DD

Links

A

Secções

DIV

Page 25: HTML - How To

2009.03.04 HTML/XHTML

MARKUP - TEXTO

<h1>Bolo de Nozes</h1>

<h2>Preparação</h2>

<p>Deite num recipiente 100g de margarina e 100g de açúcar e amasse muito bem até amolecer.</p>

<p><img src= “/media/bolo1.jpg” /></p>

<p>...</p>

Page 26: HTML - How To

2009.03.04 HTML/XHTML

MARKUP - LISTAS

<h1>Bolo de Nozes</h1>

...

<h2>Ingredientes</h2>

<ul>

<li>99 ovos</li>

<li>31 nozes</li>

...

</ul>

Page 27: HTML - How To

2009.03.04 HTML/XHTML

MARKUP - LINKS

<h1>Bolo de Nozes</h1>

...

<h2>Receitas Relacionadas</h2>

<ul>

<li><a href= “/receitas/foo”>foo</a></li>

<li><a href= “/receitas/foo”>foo</a></li>

...

</ul>

Page 28: HTML - How To

2009.03.04 HTML/XHTML

MARKUP (FORMS)

Form

FORM, FIELDSET

Controls

INPUT type=“hidden|text|radio|checkbox|file|password|submit|reset”

TEXTAREA

SELECTtype=“multiple”

Page 29: HTML - How To

2009.03.04 HTML/XHTML

FORGOTTEN “TAGS”

LABEL

DL, DT, DD

<label for=“userpass”>Password</label><input type= “password” id=“userpass” />

<dl><dt></dt><dd></dd>

</dl>

XHTML

Page 30: HTML - How To

2009.03.04 HTML/XHTML

DOCUMENT STRUCTURE

<!DOCTYPE ... >

<html>

<head>

...

</head>

<body>

...

</body>

</html>

Declarações

Cabeçalho

Conteúdo

Page 31: HTML - How To

2009.03.04 HTML/XHTML

HEADER

TITLE

META

<title>Password</title>

<meta name=“keywords”     content=“foo, bar, baz, lorem, ipsum, nozes” />

<meta http­equiv="Content­Type"     content="text/html; charset=UTF­8" />

XHTML

Page 32: HTML - How To

2009.03.04 HTML/XHTML

HEADER

SCRIPT

LINK

<script type="text/javascript" src="/js/foo.js" />

<link rel="alternate" type="application/rss+xml"   title="Feed" href="http://example.com/rss" />

<link rel="shortcut icon"    href="http://example.com/fav.ico" />

<link rel="stylesheet" type="text/css"    href="http://example.com/style/main.css" />

XHTML

Page 33: HTML - How To

2009.03.04 HTML/XHTML

DECLARAÇÕES

!DOCTYPE - indica ao browser o tipo de documento (qual o standard seguido)

<!DOCTYPE HTML PUBLIC    "­//W3C//DTD HTML 4.01//EN"     "http://www.w3.org/TR/html4/strict.dtd">

HTML

Page 34: HTML - How To

2009.03.04 HTML/XHTML

DECLARAÇÕES

No caso de XHTML... Declaração XML com indicação do encoding

Elemento HTML tem que conter atributo NAMESPACE

<!DOCTYPE html PUBLIC     "­//W3C//DTD XHTML 1.0 Strict//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1­strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"     lang="pt" xml:lang="pt">

XHTML

Page 35: HTML - How To

2009.03.04 HTML/XHTML

DECLARAÇÕES

No caso de XHTML... Declaração <?xml ?> opcional se encoding = UTF-8

Se usada a declaração IE6 entra em QUIRKS MODE!

Encoding não é = UTF-8 !?

<?xml version="1.0" encoding="UTF­8"?>

XHTML

QUIRKS MODE - WTF!?

Page 36: HTML - How To

2009.03.04 HTML/XHTML

QUIRKS MODE?

Obrigar o browser a apresentar o documento segundo as regras (?) quebradas pré-standards (IE 5.5)

Usar a declaração <?xml ... ?> IE6 entra em QUIRKS MODE!

Não declarar <!DOCTYPE ... >Praticamento todos os browsers passam a QUIRKS MODE

FAIL

Page 37: HTML - How To

2009.03.04 HTML/XHTML

TRANSITIONAL

Usar HTML deprecated (HTML 3.2, 1997) FONT, CENTER, B, I, IFRAME, ... bgcolor=“pink” target=“_blank” style=“...” name=“...”

FAIL

Page 38: HTML - How To

2009.03.04 HTML/XHTML

(DES)ESTRUTURADO FAIL

<h3>Bolo de Nozes</h3>

<h3>Ingredientes</h3>

<p>....</p>

<img ... />

<h2>Relacionados</h2>

<p>....</p>

<h1>Todos os Bolos do Mundo</h1>

Page 39: HTML - How To

2009.03.04 HTML/XHTML

DIVITIS FAIL

<div class=“receitaWrapper”><div class= “receita”>

<div class= “receitaContent”>

<div class=“title”><h2>Bolo de Nozes</h2>

</div><div class=“subtitle”>

<h3>Ingredientes</h3><p class=“link”>

<a href=“/more”><span class= “more” ...

Page 40: HTML - How To

2009.03.04 HTML/XHTML

SEMÂNTICA (1) FAIL

<div class=“receita”><p class=“title”>Bolo de Nozes</p><strong class=“texto”>

Deite num recipiente 100g de margarina e 100g de açúcar e amasse <span class=“strong”>muito bem</span> até amolecer.<br />

Junte...</strong><blockquote class=“danger”>...</blockquote>

</div>

Page 41: HTML - How To

2009.03.04 HTML/XHTML

SEMÂNTICA (2) FAIL

<div class=“roundedBox”><h2 class=“shadow”>Bolo de Nozes</h2><p class=“gray”>

Deite num recipiente 100g de margarina e 100g de açúcar e amasse <strong class=“yellowItalic”>muito bem</strong> até amolecer.

</p><a class=“orangeBig” href=“...”>...</a>

</div>

Page 42: HTML - How To

2009.03.04 HTML/XHTML

NÃO-CONTEÚDO FAIL

<a href=“/about” class=“header”><img src=“about.png” />

</a>

<div class=“title”><img src=“receitas.png” />

</div>

<a href=“/about”>...</a> | <a ...

Page 43: HTML - How To

2009.03.04 HTML/XHTML

COMENTÁRIOS COOL

STDOUT/STDERR

<!-- BEGIN receitas/list/default --><!-- created: 2009-03-04 12:30 --><!-- expires: 2009-03-04 14:00 -->

<div class=“receitas”>...

</div>

<!-- /END receitas/list/default -->

Page 44: HTML - How To

2009.03.04 HTML/XHTML

STANDARDS COOL

Validador W3Chttp://validator.w3.org/check

DTD Recomendadoshttp://www.w3.org/QA/2002/04/valid-dtd-list.html

Web-Standards Projecthttp://www.webstandards.org/

XTHML vs content-typehttp://h3h.net/2005/12/xhtml-harmful-to-feelings/http://www.456bereastreet.com/archive/200501/the_perils_of_using_xhtml_properly/

Page 45: HTML - How To

2009.03.04 HTML/XHTML

EDITORES TEXTO COOL

Open Syntax-highlight Auto-complete Auto-format

Save as “desktop/test.(x)html”

Abrir no(s) browser(s) ;-)

Page 46: HTML - How To

2009.03.04 HTML/XHTML

EXTENSÕES FF COOL

FIREBUG (inspect/test html, css, js, headers, ...)http://www.youtube.com/results?q=firebug

TIDY (validate html - error/warn - line# + why?)http://users.skynet.be/mgueury/mozilla/

WEB-DEVELOPER (enable/disable css, js, ...)https://addons.mozilla.org/en-US/firefox/addon/60

Page 47: HTML - How To

2009.03.04 HTML/XHTML

REFERÊNCIAS COOL

W3C (specs completos, linguagem muito técnica)http://www.w3.org/html/

W3SCHOOLS (rápido, incompleto, impreciso...)http://www.w3schools.com/xhtml/

WIKIPEDIA (ah pois...)http://en.wikipedia.org/wiki/Html

Page 48: HTML - How To

2009.03.04 HTML/XHTML

EXEMPLOS BONS/MAUS COOL

WWW (inspect/test html, css, js, headers, ...)

Dicas que estamos perante um bom exemplo:

MARKUP válido (check tidy!) MARKUP mínimo MARKUP semântico MARKUP comentado

Exemplo máximo: bom MARKUP não precisa de ser alterado quando muda o layout:

a.k.a. link do costume: http://www.csszengarden.com/

Page 49: HTML - How To

2009.03.04 HTML/XHTML

MESTRES COOL

ALA (A List Apart)http://www.alistapart.com/topics/code/htmlxhtml/

456BEREASTREET (Roger Johansson)http://www.456bereastreet.com/

Muitos mais...http://perguntem.ao.andr3.net