web development and html - github pages · web development •to build a website that serves web...

33
Web Development and HTML Shan-Hung Wu CS, NTHU

Upload: others

Post on 25-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Web Development and HTML

Shan-Hung Wu

CS, NTHU

Page 2: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Outline

• How does Internet Work?

• Web Development

• HTML

– Block vs. Inline elements

– Lists

– Links and Attributes

– Tables

– Forms

2

Page 3: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Outline

• How does Internet Work?

• Web Development

• HTML

– Block vs. Inline elements

– Lists

– Links and Attributes

– Tables

– Forms

3

Page 4: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

What Happened?

https://www.wikipedia.org/wiki/Node.js

4

Page 5: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

From URL to Web Page

https://www.wikipedia.org/wiki/Node.js

5

Page 6: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

HTTP

• A protocol is language spoken by machines

– Defines structure of messages to be exchanged

• HyperText Transfer Protocol (HTTP) defines:

– Messages: HTTP request and HTTP response

– Requests: accessing resources (web pages) via GET, POST, PUT, and DELETE methods

– Responses: 200 OK, 301 Moved, 404 Not Found, 500 Server Error, etc.

6

Page 7: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

HTTP Messages

• Each HTTP message have

– Initial line, header lines, and optionally body

• A resource can have different presentations

– HTML, XML, JSON, etc.7

Request:GET /wiki/Node.js HTTP/1.1

Host: www.wikipedia.org

Accept: text/html,

application/json

Response:HTTP/1.1 200 OK

Content-Type: text/html

Content-Length: 3324

<!DOCTYPE html>

<html>

<head> ... </head>

<body> ... </body>

</html>

Page 8: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Chrome Inspector

8

Page 9: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

URI vs. URL vs. URN

• An Uniform Resource Identifier (URI) identifies a resource on the Internet

• An Uniform Resource Locator (URL) is a specialized URI that identifies a resource by reachable location– E.g., “http://…”, “https://…”, “ftp://…”

– Case sensitive

– Must be URL encoded• “http://host/hello world!” “http://host/hello%20world%21”

• An Uniform Resource Name (URN) is a specialized URI that identifies a resource by name– E.g., “urn:isbn:0451450523”

9

Page 10: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Outline

• How does Internet Work?

• Web Development

• HTML

– Block vs. Inline elements

– Lists

– Links and Attributes

– Tables

– Forms

10

Page 11: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Web Development

• To build a website that serves web pages• Code to be run at client side (front end):

– Displays pages– Interacts with user– Sends additional requests

• Code to be run at server side (back end):– Handles requests (from multiple clients)– Stores data– Sends “personalized” responses

• We focus on client-side development for now

11

Page 12: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

What’s Inside a Web Page?

• Hyper-Text Markup Language (HTML)

– Content and structure

• Cascade Style Sheet (CSS):

– Styles (e.g., color, font, width, height, etc.)

• Javascript:

– Interactions

– A general-purpose programming language

12

Page 13: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Javascript Lies beyond Browsers

13

Page 14: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Hello HTML

14

Page 15: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Grammar

<tag> content </tag>

15

Page 16: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Core HTML Elements

<!DOCTYPE html>

<html>

<head>

<!-- Metadata goes here -->

<title>...</title>

</head>

<body>

<!-- Content goes here -->

</body>

</html>

16

Page 17: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Block vs. Inline Elements

• A block element:– Creates new lines above and under

– Can contain text and other block/inline elements

– Unless specified, has height fitting its content

– Unless specified, has width fitting its container

• An inline element:– Creates no new line

– Can contain only text and other inline elements

– Unless specified, has width and height fitting its content

17

Page 18: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Viewport & Responsiveness

<meta name="viewport" content="width=device-width, initial-scale=1.0">

18

Page 19: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Outline

• How does Internet Work?

• Web Development

• HTML

– Block vs. Inline elements

– Lists

– Links and Attributes

– Tables

– Forms

19

Page 20: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Block vs. Inline Elements I

• Block elements (by default):

– <h1>-<h6>, <p>, <div>, <ol>, <ul>, <li>, <table>, <form>, <hr>

• Inline elements (by default):

– <a>, <img>, <em>, <span>, <label>, <input>, <button>, <br>

• Empty elements (no content):

– <hr>, <br>, <img>

20

Page 21: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Block vs. Inline Elements II

• A block element:– Creates new lines above and under

– Can contain text and other block/inline elements

– Unless specified, has height fitting its content

– Unless specified, has width fitting its container

• An inline element:– Creates no new line

– Can contain only text and other inline elements

– Unless specified, has width and height fitting its content

21

Page 22: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

MDN Reference

22

Page 23: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Lists

<ul>

<li>List Item 1</li>

<li>List Item 2</li>

</ul>

<ol>

<li>List Item 1</li>

<li>List Item 2</li>

</ol>

23

Page 24: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

HyperLinks and Attributes

<a href="www.example.com">Text</a>

<img src="corgi.png" alt="Corgi">

24

Page 25: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Tables

<table><tr>

<th>Header 1</th><th>Header 2</th>

</tr><tr>

<td>Cell (1,1)</td><td>Call (1,2)</td>

</tr><tr>

<td>Cell (2,1)</td><td>Cell (2,2)</td>

</tr></table>

25

Page 26: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Forms I

26

Page 27: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Forms II

<form action="/sign-in-url"

method="post">

<label for="acc">Accont:</label>

<input id="acc" type="text”

name="account">

<label for="pw">Password:</label>

<input id="pw" type="password”

name="passwd">

<button>Login</button>

</form>

27

Page 28: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Query Strings

http://...?name1=val1&name2=val2

• GET resources/pages conditionally

– Based on device type, locale, etc.

• Passing arguments in POST

– E.g., account and password in user login

28

Page 29: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Form Validation

<form action="..." method="...">

...

<input ... required>

...

<input ... required>

...

</form>

29

Page 30: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Entities

• How to type ‘<’ in content?<p>a < b</p>

• < &lt;

• > &gt;

• & &amp;

• " &quot;

• Space &nbsp;

30

Page 31: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Assigned Reading

• HTML5 tutorial

31

Page 32: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Reference

• Mozilla Developer Network (MDN)

32

Page 33: Web Development and HTML - GitHub Pages · Web Development •To build a website that serves web pages •Code to be run at client side (front end): –Displays pages –Interacts

Exercise

33