+ All Categories
Home > Documents > HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5 Here...

HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5 Here...

Date post: 06-Jul-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
28
HTML and CSS Lecture 15 – COMPSCI111/111G SS 2018
Transcript
Page 1: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

HTML and CSSLecture 15 – COMPSCI111/111G SS 2018

Page 2: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Essential Tags

HTML5 022

• HTML5 requires the following tags to be in yourhtml source file:– html– head– title– body

Page 3: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Block-level tags

Define the structure of a “block”

u Headings

u Paragraphs

u Lists

u Tables

u Preformatted text

HTML5 023

Page 4: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Paragraphs<p>

u Defines a paragraph of text

HTML5 02 4

<html lang="en"><head><meta charset="UTF-8"><title>Introduction to tags</title></head><body><p>This is a very simple web page</p><p>It contains two different paragraphsof text.</p></body></html>

Page 5: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Headings

Six levels of headings

u <h1> First level headingu <h2> Second level headingu <h3> Third level headingu <h4> Fourth level heading

u <h5> Fifth level heading

u <h6> Sixth level heading

HTML5 028

Page 6: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Headings

HTML5 029

<html lang="en"><head><meta charset="UTF-8"><title>Introduction to tags</title></head><body><h1>A very simple web page</h1><p>It contains two paragraphs and two headings</p><h2>Second section</h2><p>This section is less important</p></body></html>

Page 7: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Example of Head, Heading and Title<html><head>

<meta charset=“UTF-8”><title> Titles, headings and heads</title>

</head><body>

<h1>Title</h1><p>The title is part of the document head</p>

<h2>Head</h2><p>The head is not shown on the page</p>

<h2>Heading</h2><p>These come in different sizes and make up the content of the page. They should therefore be used only in the body.</p><p>Do not get confused</p>

</body></html>

HTML5 02 10

Page 8: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Ordered Lists

Ordered Lists

u Automatically numbered

u <ol> … </ol> Contains the entire list

u <li> … </li> Used for each list item

HTML5 02

11

<p>Structure of an HTML document</p><ol><li>HTML</li><li>HEAD</li><li>BODY</li></ol>

Page 9: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Unordered Lists

Unordered Lists

u Bullet Points

u <ul> … </ul> Contains the entire list

u <li> … </li> Used for each list item

HTML5 02 12

<p>Structure of an HTML document</p><ul><li>HTML</li><li>HEAD</li><li>BODY</li></ul>

Page 10: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Description ListsTerms and explanations

u <dl> … </dl> Contains the entire list

u <dt> … </dt> Defines a term in a description list

u <dd> … </dd> Is used to describe a term in a description list

HTML5 02 13

<p>Some definitions</p><dl><dt>HTML</dt><dd>Hypertext Markup Language</dd></dl>

Page 11: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Tables

HTML5 02 14

<table>– Used to format tables of information– By default, there are no borders shown

Page 12: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Tags required to format Tables

HTML5 02 15

Row

<tr><td> … </td><td> … </td>

</tr>

Data

Tags– <table> … </table> Surrounds the entire table– <tr> … </tr> Identifies a row in the table– <td> … </td> Each element/cell of data in the row

Page 13: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

A simple table example

HTML5 02 16

<html lang="en"><head>

<meta charset=“UTF-8”><title>Simple Table</title>

</head><body><p>What follows is a simple table:</p><table><tr><td>One

</tr></table></body></html>

Row</td><td>TwoColumns</td>

Page 14: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Table ExerciseExercise 1: Write a fragment of HTML5 code that will generate a table with 2 rows and 1 column. The text in the first row should be “first row” and the text in the second row should be “second row”.

HTML5 01 19

<html><head><meta charset=“UTF-8”>

<title>Simple Table</title></head><body><p>What follows is a simple table:</p><table>

<tr><td>first row</td></tr><tr><td>second row</td></tr>

</table></body>

</html>

Page 15: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Inline tags

u Appear within the blocks

u Apply to words within paragraphs etc.

u Common inline tags

u Line Breaks

u Images

u Hypertext References

HTML5 02 20

Page 16: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Empty tags

u Tags that apply at a given point

u Do not format content

u Only the opening tag is required.

u Line breaks

u <br>

u Images

u <img>

HTML5 02 21

Page 17: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Line break

u Breaks a line

u Same as hitting the Enter key

u Use <br>

HTML5 02 22

<p>Hello Class</p><p>Hello<br>Class</p>

Page 18: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Images

u Pages may contain images

u But images are not plain text

u Can’t be inserted directly into HTML page

u Solution

u Store the image on the internet (or locally on disk)

u Tag contains the address of the image

u Web browser loads image when required

u Only use images the browser understands

u GIF, JPG, PNG

HTML5 02 23

Page 19: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Image tag

<img>

u Insert an image at this location

src

u The source file of the image

u Attribute that specifies the file name

alt

u Attribute to specify alternate text

u Displayed if the image can’t load

u Important for people with visual impairment

<img src="filename" alt="description">

HTML5 02 24

Page 20: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

<img> example

An image is inserted inline, so it is used inside a block-level element (a paragraph in this example).

HTML5 0225

<p>Here is one of my holiday pictures.<img src="Empire.jpg" alt="The Empire State Building">It was late December and it was very cold.</p>

Page 21: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Hypertext referenceA link to another resource on the WWW

u References to other documents

u Pages, images, files, sections

<a>

u Anchor tag

href

u Attribute used to specify the destination of the link

u URL

<a href="…url…">link text</a>

HTML5 02 26

Page 22: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

URLsFully specified

u Protocol

u Host name

u Path

u File

Relative

u Omit the first parts

u Path and file

u File

http://www.cs.auckland.ac.nz/courses/compsci111/index.html

/courses/compsci111/index.html

lectures/index.html

index.html

HTML5 0227

Page 23: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

HTML5 Exercise

HTML5 02 29

Exercise 1: What HTML5 code is required to create a hypertext reference that links to a page at the location "http://www.cs.auckland.ac.nz/courses/compsci111/".The underlined link on the page should be the text “111 home page”.

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Simple Page</title></head><body><p> <a href="http://www.cs.auckland.ac.nz/courses/compsci111/">111 home page</a></p></body></html>

Page 24: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Validated Codeu Online system to check correctness of code

u Provided by W3C

u http://validator.w3.org

HTML5 02 30

Page 25: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Example

HTML5 02 31

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"> <title>A sample page</title></head><body><h1>Example</h1><p>This is a complete html5 web page. You can verify that all thecode is correct using the <a href="http://validator.w3.org">W3C Validator</a>.</p><h2>Images</h2><p>If your code is correct, you will get this message showing thatyour page has validated.</p><p><img src="validated.png" alt="Validated html5"></p><p>Author: Damir Azhar<br>Date: 19/01/15<br></p></body></html>

Page 26: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Example page

HTML5 02 32

Page 27: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

Sections• <section> tag defines a section in a HTML5

document.

• Can be used to split a web page into different sections.

• Is an example of a semantic element.

• An element that clearly defines its content to both the browser and the developer.

HTML5 02 33

Page 28: HTML and CSS - Computer Science · HTML and CSS Lecture 15 –COMPSCI111/111G SS 2018. ... 5  Here is one of my holiday pictures.

<section> example

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Section Tag Example</title></head><body><h1>About Me</h1>

<section><h2>Work</h2><p>Most of my work centres around COMPSCI 111 where I:</p><ul><li>Lecture</li><li>Run labs</li></ul></section>

<section><h2>Interests</h2><p>My interests include:</p><ul><li>Gaming</li><li>Reading</li></ul></section>

</body></html>

HTML5 02 34


Recommended