• No results found

TDP013. Webbprogrammering och interaktivitet. Introduktion, HTML5, CSS & Selenium

N/A
N/A
Protected

Academic year: 2022

Share "TDP013. Webbprogrammering och interaktivitet. Introduktion, HTML5, CSS & Selenium"

Copied!
77
0
0

Loading.... (view fulltext now)

Full text

(1)

Webbprogrammering och interaktivitet
 Introduktion, HTML5, CSS & Selenium

TDP013

Anders Fröberg (

anders.froberg@liu.se

)

Institutionen för Datavetenskap (IDA)

(2)

Kursens nyckelpersoner

!2

Examinator: Anders Fröberg Kursansvarig: Anders Fröberg

Kursssistenter: Mattias och Tore

Kontakta mig (anders.froberg@liu.se) gällande frågor om kursen.

Kontakta kursassistent för hjälp kring laborationerna.

(3)

Kursens design

!3

I högskoleförordningen står det under mål för kandidatexamina bland annat att:

För kandidatexamen skall studenten - visa förmåga att söka, samla, värdera och kritiskt tolka relevant information i en problemställning samt att kritiskt diskutera företeelser, frågeställningar och situationer, - Högskoleförordningen (1993:100)

Kursen är byggd på ett sätt som lägger stor vikt vid att ge

studenterna möjlighet att själva söka efter den information som behövs för att lösa de innefattande laborationerna.

Föreläsningarna är tänkta att introducera ämnena och hjälpa

studenterna att komma igång med sin informationssökning.

(4)

Kursens litteratur

!4

Det finns ingen officiell tryckt litteratur till kursen.


Varje föreläsning redovisar för dess referenser på kurshemsidan.


Tänk på examina-målet!

visa förmåga att söka, samla, värdera och kritiskt tolka relevant information i en

problemställning samt att kritiskt diskutera företeelser, frågeställningar och situationer


Kursens kunskapsfilosofi

(5)

Kursens innehåll

!5

Kursen behandlar webbteknik med fokus på programmering av webbapplikationer.

Kursen består av ett antal programmeringsuppgifter (laborationer) som behandlar viktiga teknikdelar som HTML5, CSS, JavaScript för klient och server

(node.js+express) samt MongoDB.

Ett större programmeringsprojekt genomförs slutligen.

Kursen bygger i stor grad på egen programmering.

Examination sker genom muntlig demonstration och presentation av funktion och kod.

Etik inom mjukvarutveckling

(6)

Kursens examination

!6

Laborationer och projekt görs i par och registreras i webreg i

vanlig ordning. Instruktionerna för varje laboration visar tydligt vilka kurs-, program- och examensmål laborationen är tänkt att

examinera.

För godkänt i kursen skall laborationerna genomföras, men

graderat betyg avgörs av projektet. Mer info på kurshemsidan.


(7)

Kursens tekniska innehåll

!7

Klientsida (dvs det användaren ser och som körs i webbläsaren)

HTML, CSS, JavaScript ->HTML5


Serversida (dvs det som körs på en datorn någonstans som innehåller all information som skall visas)

Node.js+Express.js (JavaScript) och MongoDB (databas)


Förutom detta kommer vi titta på olika verktyg för att

testa klient och serversida.

(8)

Varför utvecklar vi webbapplikationer?

Skrivbords applikation

Outlook 2003 släpps Användare köper och

installerar.

Outlook 2007 släpps Nu krävs ny marknadsföring och skeppning av produkter

till butiker

Användare behåller det gamla office paketet, tycker

inte det behöver

uppdateras, eller vet kanske inte ens om att man kan

uppdatera.

Mr Gates

Mr Gates

(9)

Varför utvecklar vi webbapplikationer?

Skrivbords applikation Webbapplikation

Outlook 2003 släpps Användare köper och

installerar.

Outlook 2007 släpps Nu krävs ny marknadsföring och skeppning av produkter

till butiker

Användare behåller det gamla office paketet, tycker

inte det behöver

uppdateras, eller vet kanske inte ens om att man kan

uppdatera.

Mr Gates

Mr Gates

Office 365 lanseras Användare skapar konto på

nätet och betalar en liten summa varje månad.

Nya uppdateringar görs av sidan

Nästa gång användaren loggar in syns dessa nya

ändringar

Användare får direkt tillgång till nya uppdateringar utan

att man behöver marknadsföra dessa till existerande kunder eller

skeppa till butiker.


Inkomsterna är kontinuerliga varje månad, så länge

kunderna är nöjda.

Mr Nadella

Mr Nadella

(10)

Varför använder vi webbapplikationer ?

• Inga installationer (om datorn har en webbläsare).

• Om man sitter hemma hos någon eller på

internetcafé spelar ingen roll, så länge man har en webbläsare och internet.

• Samma filer på alla datorer man loggar in från.

• Kan logga in från hela världen och t ex läsa sin mejl.

En av de bästa saker med Facebook är att personer kan använda det på t ex semestern eller jobbet, från vilken dator som helst.


Tänk om Facebook varit en skrivbords

applikation som skulle installeras på datorn, hade företaget blivit värderat till $50

miljarder dollar under 2011 ?

(11)

Server

Kapitel 1 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Avsnitt 1 Vestibulum venenatis, velit sed cursus ultricies, sem nisi fringilla erat.

1. Hämtar ett rent text dokument, användaren kan läsa med viss svårighet.

(12)

Server

Kapitel 1 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Avsnitt 1 Vestibulum venenatis, velit sed cursus ultricies, sem nisi fringilla erat.

1. Hämtar ett rent text dokument, användaren kan läsa med viss svårighet.

<h1>Kapitel 1</h1>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p>

<h2>Avsnitt 1</h2>

<p>Vestibulum venenatis, velit sed cursus ultricies, sem nisi fringilla erat.</p>

2. Hämtar ett HTML dokument, hjälper inte användaren att läsa, blir bara värre.

(13)

Server

Kapitel 1 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Avsnitt 1 Vestibulum venenatis, velit sed cursus ultricies, sem nisi fringilla erat.

1. Hämtar ett rent text dokument, användaren kan läsa med viss svårighet.

<h1>Kapitel 1</h1>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p>

<h2>Avsnitt 1</h2>

<p>Vestibulum venenatis, velit sed cursus ultricies, sem nisi fringilla erat.</p>

2. Hämtar ett HTML dokument, hjälper inte användaren att läsa, blir bara värre.

Kapitel 1

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Avsnitt 1

Vestibulum venenatis, velit sed cursus ultricies, sem nisi fringilla erat.

3. Om vi låter vår webbläsare få ta hand om HTML dokumentet, så visar den upp ett läsbart och indelat dokument.

(14)

Det finns många webbläsare på marknaden, och de är inte alla lika. 


Därför kan man ibland bli lite förvånad över hur ens webbplats ser ut på olika webbläsare.

Eftersom webbläsare kan rendera HTML lite olika är det viktigt att

testa sin webbplats på flera läsare under utvecklingens gång.

(15)

HTML

Syntax and structure

(16)

HTML5

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>Document 1</title>

</head>

<body>

<p>The first and only paragraph.</p>

</body>

</html>

(17)

HTML5

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>Document 1</title>

</head>

<body>

<p>The first and only paragraph.</p>

</body>

</html>

⁃ Elements start + end

attributes + values content

⁃ Elements can be nested, but may not overlap.

(18)

Tag syntax

⁃ Docyment type

<!doctype html>

⁃ Non-closing tag

<tag>

⁃ Start and end tag

<tag>content</tag>

⁃ Non-closing tag with an attribute+value

<tag attribute="value">

⁃ Start and end tag with attribute+value

<tag attribute="value">content</tag>

(19)

DOM tree - family relationships

(20)

Syntax

⁃ Whitespace (tab, space, return) is not significant. Still, you should keep your code tidy.

⁃ Character case does not matter, but use lower case letters for tags

(21)

HTML defines structure

⁃ semantic use

for search engines

⁃ organizational use

prepare for css styles prepare for interaction

(22)

Comments

⁃ Make comments to disable parts of your HTML code or to annotate your code

<!-- This is a comment -->

(23)

Headings

<h1>Heading 1</h1>

<h2>Heading 2</h2>

<h3>Heading 3</h3>

<h4>Heading 4</h4>

<h5>Heading 5</h5>

<h6>Heading 6</h6>

(24)

Paragrphs

<p>paragraph 1</p>

<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.</p>

<p>paragraph 3</p>

<p>paragraph 4</p>

(25)

Links

<a href="url">Link text</a>

(26)

Images

<img src="url">

(27)

Structural elements

(28)

Structural elements

⁃ A block of something <div> </div>

⁃ An inline element <span> </span>

(29)

Semantic elements in HTML5

<header>

<nav>

<section>

<article>

<aside>

<figcaption>

<figure>

<footer>

http://www.w3.org/TR/html5/

(30)

Validering av HTML kod

• http://validator.w3.org


• Korrekt skriven HTML kod gör att webbläsaren inte behöver gissa hur den skall tolka koden


• Detta leder till att din webbplats har större chans att se ut som du tänkt dig i alla webbläsare

• I laborationsserien skall koden valideras som HTML5

• Om du har fel, rätta ett i taget tills du får ”grönt”

(31)

CSS

https://developer.mozilla.org/en-US/docs/Web/CSS http://www.w3schools.com/css/default.asp

(32)

CSS (Cascading Style Sheets)

⁃ CSS specifies

1.visual style 2.layout

⁃ HTML elements inherit CSS properties from their ancestors

e.g. the value of the font-family property for the body element is inherited by the p element.

(33)

Aspects of style

⁃ colors and borders, e.g.

background color/image borders around elements

⁃ typography, e.g.

font, font size line height

⁃ size of elements

(34)

Aspects of layout

⁃ Interaction between elements (e.g. what happens when two elements want to use the same space)

⁃ Size of elements

⁃ Positioning of elements

(35)

The style sheet

⁃ Plain text file

⁃ A collection of style specifications

⁃ A HTML document can link to one or more stylesheets

⁃ Style specifications are evaluated in serial from the top.

⁃ Later specifications can overrule previous specifications.

(36)

declaration block

Syntax

selector

value

declaration

p { color:red; font-size:16px; }

property

(37)

Syntax

/* This is a comment */

body {

font-family: Times, Serif;

font-size: 16px;

padding: 0px 0px 0px 0px;

} h1 {

font-family: Helvetica, Sans-Serif;

font-size: 32px;

}

(38)

Some CSS length units

⁃ Reference:

https://developer.mozilla.org/en-US/docs/Web/CSS/length

px

pixels on screen

note: a CSS pixel is not the same as a screen pixel see

http://inamidst.com/stuff/notes/csspx

em

1em = inherited font-size, 2em = double inherited font-size

rem

1rem = font-size of root element

pt

point, 1pt = 1/72 inch

(39)

Some CSS length units

%

percent of inherited size

vw

1vw = 1% of width of the viewport's initial containing block (i.e. the

<html> block in most cases)

vh

1vh = 1% of height of the viewport's initial containing block (i.e. the

<html> block in most cases)

vmin

1vmin = 1% of the smallest viewport unit, either vh or vw

vmax

1vmax = 1% of the largest viewport unit, either vh or vw

(40)

HTML + CSS

⁃ Text files

⁃ CSS can be written in the same file, but we will use an external file.

⁃ Link HTML and CSS using the link tag in the header

(41)

page.html & style.css

<!doctype html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>A document</title>

<link rel="stylesheet" href="style.css">

</head>

<body>

<h1>The Heading</h1>

<p>The paragraph</p>

<body>

</html>

body {

font-family: Times, Serif;

font-size: 16px;

padding: 0px 0px 0px 0px;

} h1 {

font-family: Helvetica, Sans-Serif;

font-size: 32px;

}

(42)

Filepaths in HTML and CSS

⁃ Unless otherwise specified, all filepaths are relative to the current file.

/ means the root of the web site, i.e. for

https://www-und.ida.liu.se/~yourliuid/index.html the root is

https://www-und.ida.liu.se/

../ means go up one directory

(43)

Examples of properties

(44)

Some style properties HTML elements

font-size: size of font

font-family: name of font

line-height: height of linne

width: width of element

height: height of element

margin: distance to next element

padding: distance to element content

color: font color

background-color: background color of element

border: border style of element

(45)

Basic CSS

https://jsfiddle.net/bgfvdo18

(46)

A selection of

selectors

(47)

Selecting your selector

⁃ Targeting a group of elements

"select all paragraphs and list items"

⁃ Targeting adjacent siblings

"select all paragraphs that directly follow a heading"

⁃ Targeting descendants

"select any image that is inside a <article>"

⁃ Targeting children

"select all first level list items in unordered lists with the class 'toc'"

https://developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS/Selectors http://www.w3.org/TR/selectors/

(48)

Select a group of elements

/* Target all h1, h2 and h3 element */

h1, h2, h3 {

border: 2px solid #000;

}

(49)

Descendant combinator

/* Select all li element that are nested within a nav element. */

nav li {

color: #F00;

}

(50)

Child combinator

/* Target all p elements that are children of a div */

div > p {

border: 2px solid #000;

}

(51)

Adjacent sibling combinator

/* Target all p elements that are on the same level as a h1 and follow a h1 */

h1 + p {

font-weight: bold;

}

(52)

Pseudo selectors

:hover

Select elements that the mouse is hovering above e.g. a:hover

:visited

Select elements (i.e. links) that have been visited e.g. a:visited

(53)

CSS Reset

(54)

CSS Resets

⁃ Browsers come with default stylesheets.

⁃ Some default styles differ between browsers.

⁃ CSS Reset: CSS that sets the style of these properties to known values ~ common baseline style.

⁃ Eric Meyer's CSS reset from 2011


https://meyerweb.com/eric/tools/css/reset/reset.css

⁃ Normalize.css


http://nicolasgallagher.com/about-normalize-css/

⁃ Reboot, Resets, and Reasoning


https://css-tricks.com/reboot-resets-reasoning/

(55)

Classes and id:s

(56)

What is a class? When should I use it?

⁃ Elements can be assigned one or more classes

⁃ More than one element can be assigned the same class.

⁃ Use classes for recurring components of your web page.

⁃ The prefix . (dot) is used to in front of class names in CSS selectors.

⁃ HTML start tag examples:

<div class="box">, <div class="box green-bg">

⁃ CSS selector examples:

.box, div.box, div.box.green-bg, green-bg

(57)

Example of using multiple classes

.wrapper { width: 960px;

}

.green-bg {

background-color: green;

}

.yellow-bg {

background-color: yellow;

}

.blue-fg { color: blue;

}

.box {

border: 1px solid purple;

width: 100px;

height: 100px;

}

<div class="wrapper">

<div class="green-bg box">Box 1</div>

<div class="green-yellow box">Box 2</div>

<div class="box blue-fg">Box 3</div>

<!-- If multiple classes conflict, the order of their specification in the CSS file governs priority -->

<div class="green-bg yellow-bg box">Box 4</div>

</div>

(58)

Multiple classes

https://jsfiddle.net/he3x2yLw/1/

(59)

What is an id? When should I use it?

⁃ Elements can be assigned an id

⁃ An id can only be assigned to a single element in a HTML document.

⁃ Use ids for unique elements on your page that you want to target for a specific style.

⁃ The prefix # (octothorpe, hash sign, pound sign) is used in front of id:s in CSS selectors.

⁃ HTML start tag examples:

<div id="footer">, <h1 id="main-heading">

⁃ CSS selector examples:

#footer, div#footer, h1#main-heading, #main-heading

(60)

Selectors using classes and ids

.infobox {

font-family: Helvetica, Arial, Sans-Serif;

font-size: 0.9em;

background-color: #999;

color: #000;

border: 2px solid black;

}

#menu {

background-color: #000;

color: #FFF;

}

(61)

Colors and borders

(62)

Specifying color: RGB

⁃ Red, Green, Blue - Additive color model

⁃ Values from 0-255 (decimal) or 0-F or 00-FF (hex)

⁃ Black

rgb(0, 0, 0) or #000 or #000000

⁃ White

rgb(255, 255, 255) or #FFF or #FFFFFF

⁃ Purple

rgb(128, 0, 255) or #8000FF

(63)

Specifying color: named colors

⁃ CSS Level 1: black, silver, gray, white, maroon, red, purple, fuchsia, green, lime, olive, yellow, navy, blue, teal, aqua

⁃ CSS Level 2 (Revision 1): + orange

⁃ CSS Color Module Level 3: + aliceblue, antiquewhite, aquamarine, azure, beige, bisque, blanchedalmond, blueviolet, brown, burlywood, cadetblue, chartreuse, chocolate, coral, cornflowerblue, cornsilk, crimson, cyan (synonym of aqua), darkblue, darkcyan, darkgoldenrod, darkgray, darkgreen, darkgrey, darkkhaki, darkmagenta, darkolivegreen, darkorange, darkorchid, darkred, darksalmon, darkseagreen, darkslateblue, darkslategray, darkslategrey, darkturquoise, darkviolet, deeppink, deepskyblue, dimgray, dimgrey,

dodgerblue, firebrick, floralwhite, forestgreen, gainsboro, ghostwhite, gold, goldenrod, greenyellow, grey, honeydew, hotpink, indianred, indigo, ivory, khaki, lavender, lavenderblush, lawngreen, lemonchiffon, lightblue, lightcoral, lightcyan, lightgoldenrodyellow, lightgray, lightgreen, lightgrey, lightpink, lightsalmon, lightseagreen, lightskyblue, lightslategray, lightslategrey, lightsteelblue, lightyellow, limegreen, linen, magenta, (synonym of fuchsia), mediumaquamarine, mediumblue, mediumorchid, mediumpurple, mediumseagreen, mediumslateblue, mediumspringgreen, mediumturquoise, mediumvioletred, midnightblue, mintcream, mistyrose, moccasin, navajowhite, oldlace, olivedrab, orangered, orchid, palegoldenrod, palegreen, paleturquoise, palevioletred, papayawhip, peachpuff, peru, pink, plum, powderblue, rosybrown, royalblue, saddlebrown, salmon, sandybrown, seagreen, seashell, sienna, skyblue, slateblue, slategray, slategrey, snow, springgreen, steelblue, tan, thistle, tomato, turquoise, violet, wheat, whitesmoke, yellowgreen

⁃ CSS Color Module Level 4: + rebeccapurple

(64)

Color Inspiration

⁃ Adobe Color CC


https://color.adobe.com/explore/

⁃ material design palette


https://www.materialpalette.com/

⁃ paletton


http://paletton.com

(65)

background-color, color

h1 {

color: #fff;

background-color: #075488;

}

(66)

CSS Borders

⁃ Certain elements can have a border

⁃ A border has the following properties:

width style color

(67)

CSS Borders

⁃ Shorthand declaration

border: <width> <style> <color>

⁃ Specific properties

border-style, border-width, border-color

border-top, border-right, border-bottom, border-left border-top-style, border-top-color … etc

(68)

The CSS Box & Layout Model

https://developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS/Box_model http://learnlayout.com/toc.html

(69)

Layout models in CSS

⁃ Normal flow + positioning

display: block | inline | inline-block

⁃ Flexbox

display: flex

⁃ Grid layout

display: grid

⁃ Floats

float: left | right

⁃ Table layout

⁃ Multiple-column layout

(70)

What should you use/learn?

⁃ In CSS each element

exists inside a layout context

provides a layout context for the elements in contains

⁃ Even though you create a layout using flex or grid, the contents of your flex/grid will have a normal flow.

⁃ Therefore, master normal flow + positioning + floats before learning flex/grid etc.

⁃ Flexbox and grid layout can be very useful but cannot solve everything.

(71)

Normal flow

⁃ Elements can be set to be displayed in different contexts.

⁃ Contexts for normal flow:

block inline

inline-block

⁃ The inline context is “in line with text” with the generic inline element being <span>

⁃ The block context is “outside text” with the generic block element being <div>. A block element occupies an area from left to right.

⁃ The inline-block context is a block in line with text.

(72)

The display property

/* The formatting context is set using the display property */

.infobox {

display: block;

}

.question {

display: inline;

}

(73)

The CSS box model (block context)

(74)

Specifying an elements padding

padding: <north>, <east>, <south>, <west>

padding-top: <value>;

padding-right: <value>;

padding-bottom: <value>;

padding-left: <value>;

(75)

Specifying an elements margin

margin: <north>, <east>, <south>, <west>

margin-top: <value>;

margin-right: <value>;

margin-bottom: <value>;

margin-left: <value>;

(76)

Positioning

https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning http://learnlayout.com/position.html

(77)

Four Five positioning models

position: static

position: relative

position: fixed

position: absolute

position: sticky

z-index: <number>

References

Related documents

Lorem ipsum dolor sit amet, maiores ornare ac fermentum, imper- diet ut vivamus a, nam lectus at nunc.. Quam euismod sem, semper ut potenti

Rastr parku je odvozen od rastru kolejí, jejichž torza jsou místy zachována. Umožňuje prolínání povrchů (kámen, dřevo,

Sed elementum, nibh eu ultricies scelerisque, est lorem dignissim elit, quis tempus tortor eros non ipsum.. Mauris convallis augue

Big text indent 25mm: Text here lorem ipsum ibisque

Lorem ipsum dolor sit amet consectetuer egestas arcu vitae ut urna. Nulla ipsum ligula orci nibh ut Maecenas

• Underhållsmarknaden Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua..

Ut wisi enim ad minim am, quis nostrud exerci tation Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna

Donec sed odio dui Maecenas sed diam eget risus varius blandit sit amet non magna.. Praesent commodo cursus magna, vel scele - risque nisl