web development and html
play

Web Development and HTML Shan-Hung Wu CS, NTHU Outline How does - PowerPoint PPT Presentation

Web Development and HTML Shan-Hung Wu CS, NTHU Outline How does Internet Work? Web Development HTML Block vs. Inline elements Lists Links and Attributes Tables Forms 2 Outline How does Internet Work? Web


  1. Web Development and HTML Shan-Hung Wu CS, NTHU

  2. Outline • How does Internet Work? • Web Development • HTML – Block vs. Inline elements – Lists – Links and Attributes – Tables – Forms 2

  3. Outline • How does Internet Work? • Web Development • HTML – Block vs. Inline elements – Lists – Links and Attributes – Tables – Forms 3

  4. What Happened? https://www.wikipedia.org/wiki/Node.js 4

  5. From URL to Web Page https://www.wikipedia.org/wiki/Node.js 5

  6. 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: 2 00 OK, 3 01 Moved, 4 04 Not Found, 5 00 Server Error, etc. 6

  7. HTTP Messages • Each HTTP message have – Initial line, header lines, and optionally body Request: Response: GET /wiki/Node.js HTTP/1.1 HTTP/1.1 200 OK Host: www.wikipedia.org Content-Type: text/html Accept: text/html, Content-Length: 3324 application/json <!DOCTYPE html> <html> <head> ... </head> <body> ... </body> </html> • A resource can have different presentations – HTML, XML, JSON, etc. 7

  8. Chrome Inspector 8

  9. 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

  10. Outline • How does Internet Work? • Web Development • HTML – Block vs. Inline elements – Lists – Links and Attributes – Tables – Forms 10

  11. 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

  12. 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

  13. Javascript Lies beyond Browsers 13

  14. Hello HTML 14

  15. Grammar <tag> content </tag> 15

  16. Core HTML Elements <!DOCTYPE html> <html> <head> <!-- Metadata goes here --> <title>...</title> </head> <body> <!-- Content goes here --> </body> </html> 16

  17. 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

  18. Viewport & Responsiveness <meta name="viewport" content="width=device-width, initial-scale=1.0"> 18

  19. Outline • How does Internet Work? • Web Development • HTML – Block vs. Inline elements – Lists – Links and Attributes – Tables – Forms 19

  20. 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

  21. 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

  22. MDN Reference 22

  23. 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

  24. HyperLinks and Attributes <a href="www.example.com">Text</a> <img src="corgi.png" alt="Corgi"> 24

  25. 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

  26. Forms I 26

  27. 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

  28. 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

  29. Form Validation <form action="..." method="..."> ... <input ... required > ... <input ... required > ... </form> 29

  30. Entities • How to type ‘<’ in content? <p>a < b</p> • <  &lt; • >  &gt; • &  &amp; • "  &quot; • Space  &nbsp; 30

  31. Assigned Reading • HTML5 tutorial 31

  32. Reference • Mozilla Developer Network (MDN) 32

  33. Exercise 33

Recommend


More recommend