43
Dag 2: HTML & CSS

Dag 2: HTML & CSS

Embed Size (px)

Citation preview

Page 1: Dag 2: HTML & CSS

Dag 2: HTML & CSS

Page 2: Dag 2: HTML & CSS

Mål för idag• Förstå vad en webbläsare gör

• Kunna bygga en enkel HTML-sida

• Förstå klasser och id:n

• Kunna style:a HTML-sidan med CSS

• Förstå selectors

• Vad en CSS-reset är

• Kunna göra ett par enkla CSS-layouter

Page 3: Dag 2: HTML & CSS

Hur fungerar webben?

Webbläsaren Webbservern

http://www…

HTTP

HTML

CSS & img

Django

Page 4: Dag 2: HTML & CSS
Page 5: Dag 2: HTML & CSS
Page 6: Dag 2: HTML & CSS

Webbläsare är olika

• Olika webbläsare på dator och tablet/telefon

• Olika webbläsare på olika operativsystem

• Olika versioner av webbläsare stödjer olika funktioner

Page 7: Dag 2: HTML & CSS

Hur hanterar vi det?

• Testa i olika webbläsare (installera alla de stora)

• Försök följa standarder, specifikationer…

• Använd en “reset”!

Page 8: Dag 2: HTML & CSS

Google is your friend!

Page 9: Dag 2: HTML & CSS

HTML

Page 10: Dag 2: HTML & CSS

filnamn.html<!doctype html><html>

<head><title>Testsajt!</title><meta charset="utf-8">

</head><body>

<h1>Hej!</h1><p>

Här kommer en <a href="http://google.com">Länk till Google</a>.

</p></body>

</html>

Page 11: Dag 2: HTML & CSS

filnamn.html

<!doctype html><html><head><title>Testsajt!</title><meta charset="utf-8"></head><body><h1>Hej!</h1><p>Här kommer en <a href="http://google.com">Länk till Google</a>.</p></body></html>

Page 12: Dag 2: HTML & CSS

filnamn.html<!doctype html><html>

<head><title>Testsajt!</title><meta charset="utf-8">

</head><body>

<h1>Hej!</h1><p>

Här kommer en <a href="http://google.com">Länk till Google</a>.

</p></body>

</html>

Page 13: Dag 2: HTML & CSS

Klasser och ID:n

• Klass: <div class="quote">...</div>

• Id: <div id="emil">...</div>

• Ett element kan ha flera klasser

• Flera element kan ha samma klass

• Klasser vanligast, “man vet aldrig när man ska använda något igen”

• Klass: <div class="quote important">...</div>

Page 14: Dag 2: HTML & CSS

Finns massor med taggar, Googla istället!

Page 15: Dag 2: HTML & CSS

View-source

http://tjejerkodar.se/

Page 16: Dag 2: HTML & CSS

CSS

Page 17: Dag 2: HTML & CSS

style.cssbody {

background: #EEEEEE;font: 12pt/1.4 "Helvetica Neue", "Helvetica", serif;max-width: 600px;margin: 0 auto;

}h1 {

color: #FF9999;}a {

color: #FF3333;}p {

border-bottom: 1px solid #FF9999;padding-bottom: 5px;

}

Page 18: Dag 2: HTML & CSS

style.cssbody {

background: #EEEEEE;font: 12pt/1.4 "Helvetica Neue", "Helvetica", serif;max-width: 600px;margin: 0 auto;

}h1 {

color: #FF9999;}a {

color: #FF3333;}p {

border-bottom: 1px solid #FF9999;padding-bottom: 5px;

}

Page 19: Dag 2: HTML & CSS

Box model

Page 20: Dag 2: HTML & CSS

style.cssbody {

background: #EEEEEE;font: 12pt/1.4 "Helvetica Neue", "Helvetica", serif;max-width: 600px;margin: 0 auto;

}h1 {

color: #FF9999;}a {

color: #FF3333;}p {

border-bottom: 1px solid #FF9999;padding-bottom: 5px;

}

Page 21: Dag 2: HTML & CSS

style.css

body{background: #EEEEEE;font: 12pt/1.4 "Helvetica Neue", "Helvetica", serif;max-width: 600px;margin: 0 auto;

}h1{color: #FF9999}a{color: #FF3333}p{

border-bottom: 1px solid #FF9999;padding-bottom: 5px;

}

Page 22: Dag 2: HTML & CSS
Page 23: Dag 2: HTML & CSS

Hur koppla ihop?

<!doctype html><html>

<head><title>Testsajt!</title><meta charset="utf-8"><link rel="stylesheet"

href="style.css"></head>…

Page 24: Dag 2: HTML & CSS

De olika delarna

selector {property: value;property: value value;property: ”value”;property: value;

}

Page 25: Dag 2: HTML & CSS

Selectors

tag { … } body { … } <body>...</body>

.class { … } .quote { … } <div class="quote">...

#id { … } #emil { … } <img id="emil" src="...">

Page 26: Dag 2: HTML & CSS

Kombinera selectors

img#emil { … } img.mugshot { … }

.quote p { … } p a { … }

a, p { … } .pic, .quote { … }

Page 27: Dag 2: HTML & CSS

”CSS-reset”

Normalize.css

Page 28: Dag 2: HTML & CSS

Hur gör man ”layout”?

• Finns massor av olika metoder

• Beror på vilka webbläsare man måste stödja: http://caniuse.com/#search=layout

• Mitt tips: ”display: table”

Page 29: Dag 2: HTML & CSS

HTML för tabell

<table><tr><td>Etta</td><td>Tvåa</td><td>Trea</td></tr><tr><td>Etta</td><td>Tvåa</td><td>Trea</td></tr><tr><td>Etta</td><td>Tvåa</td><td>Trea</td></tr></table>

Page 30: Dag 2: HTML & CSS

Visas såhär…

Etta Tvåa Trea

Etta Tvåa Trea

Etta Tvåa Trea

Page 31: Dag 2: HTML & CSS

En rad + högre höjd

Etta Tvåa Trea

Page 32: Dag 2: HTML & CSS

Ändra texten lite…Navigation Collaboratively administrate

empowered markets via plug-and-play networks. Dynamically procrastinate B2C users after installed base benefits. Dramatically visualize customer directed convergence without revolutionary ROI.

Efficiently unleash cross-media information without cross-media value. Quickly maximize timely deliverables for real-time schemas.

Sidebar

Page 33: Dag 2: HTML & CSS

Problem: Mobilen…Navigation

Collaboratively administrate empowered markets via plug-and-play networks. Dynamically procrastinate B2C users after installed base benefits. Dramatically visualize customer directed convergence without revolutionary ROI.

Efficiently unleash cross-media information without cross-media value. Quickly maximize timely deliverables for real-time schemas.

Sidebar

Page 34: Dag 2: HTML & CSS

Som en tabell…

<table><tr>

<td>Etta</td><td>Tvåa</td><td>Trea</td>

</tr></table>

Page 35: Dag 2: HTML & CSS

Med klasser

<div class="container"><div class="row">

<div class="column">Etta</div><div class="column">Tvåa</div><div class="column">Trea</div>

</div></div>

Page 36: Dag 2: HTML & CSS
Page 37: Dag 2: HTML & CSS

.container { display: table; width: 100%;

}.row { display: table-row; }.column { display: table-cell; }

<div class="container"><div class="row">

<div class="column">Etta</div><div class="column">Tvåa</div><div class="column">Trea</div>

</div></div>

Page 38: Dag 2: HTML & CSS
Page 39: Dag 2: HTML & CSS

Bara kolumner när det finns plats…

@media only screen and (min-width: 321px) {.container {

display: table;width: 100%;

}.row { display: table-row; }.column { display: table-cell; }

}

Page 40: Dag 2: HTML & CSS

<div class="header">Sidhuvud

</div><div class="container">

<div class="row"><div class="column">Etta</div><div class="column">Tvåa</div><div class="column">Trea</div>

</div></div><div class="footer">

Sidfot</div>

Page 41: Dag 2: HTML & CSS
Page 42: Dag 2: HTML & CSS

Centrerad layouthtml, body, .container {

height: 100%;margin: 0;

}.container {

display: table;width: 100%;

}.row { display: table-row; }.column {

display: table-cell;vertical-align: middle;

}.wrapper {

border: 1px solid black;margin: 0 auto;width: 200px;

}

<div class="container"><div class="row">

<div class="column"><div class="wrapper">

<h1>Hej!</h1><p>... på dig</p>

</div></div>

</div></div>

Page 43: Dag 2: HTML & CSS