CSS 1
CSS 2
CSS
HTML
HTML 2
HTML 3
HTML 4
HTML
CSS
JS
Lecturer: Emi Tanaka
Department of Econometrics and Business Statistics
Aim
Why
A web page consists of:
.html
.simple-example.html
<html> <body> <h1>ETC5523: Communicating with Data</h1> <h2>Lecturer</h2> <ul> <li>Emi Tanaka (Chief Examiner)</li> </ul> <h2>Tutor</h2> <ul> <li>Weihao (Patrick) Li</li> </ul> </body> </html>
<html> <body> <h1>ETC5523: Communicating with Data</h1> <h2>Lecturer</h2> <ul> <li>Emi Tanaka (Chief Examiner)</li> </ul> <h2>Tutor</h2> <ul> <li>Weihao (Patrick) Li</li> </ul> </body> </html>
<html> <body> <h1>ETC5523: Communicating with Data</h1> <h2>Lecturer</h2> <ul> <li>Emi Tanaka (Chief Examiner)</li> </ul> <h2>Tutor</h2> <ul> <li>Weihao (Patrick) Li</li> </ul> </body> </html>
<html> <body> <h1>ETC5523: Communicating with Data</h1> <h2>Lecturer</h2> <ul> <li>Emi Tanaka (Chief Examiner)</li> </ul> <h2>Tutor</h2> <ul> <li>Weihao (Patrick) Li</li> </ul> </body> </html>
<html> <body> <h1>ETC5523: Communicating with Data</h1> <h2>Lecturer</h2> <ul> <li>Emi Tanaka (Chief Examiner)</li> </ul> <h2>Tutor</h2> <ul> <li>Weihao (Patrick) Li</li> </ul> </body> </html>
<html> <body> <h1>ETC5523: Communicating with Data</h1> <h2>Lecturer</h2> <ul> <li>Emi Tanaka (Chief Examiner)</li> </ul> <h2>Tutor</h2> <ul> <li>Weihao (Patrick) Li</li> </ul> </body> </html>
<html> <body> <h1>ETC5523: Communicating with Data</h1> <h2>Lecturer</h2> <ul> <li>Emi Tanaka (Chief Examiner)</li> </ul> <h2>Tutor</h2> <ul> <li>Weihao (Patrick) Li</li> </ul> </body> </html>
<html> <body> <h1>ETC5523: Communicating with Data</h1> <h2>Lecturer</h2> <ul> <li>Emi Tanaka (Chief Examiner)</li> </ul> <h2>Tutor</h2> <ul> <li>Weihao (Patrick) Li</li> </ul> </body> </html>
<html> <body> <h1>ETC5523: Communicating with Data</h1> <h2>Lecturer</h2> <ul> <li>Emi Tanaka (Chief Examiner)</li> </ul> <h2>Tutor</h2> <ul> <li>Weihao (Patrick) Li</li> </ul> </body> </html>
<html> <!--This is a comment and ignored by web client.--> <head> <!--This section contains web page metadata.--> <title>Communicating with Data</title> <meta name="author" content="Emi Tanaka"> <link rel="stylesheet" href="css/styles.css"> </head> <body> <!--This section contains what you want to display on your web page.--> <h1>I'm a first level header</h1> <p>This is a paragraph.</p> </body> </html>
<html> <!--This is a comment and ignored by web client.--> <head> <!--This section contains web page metadata.--> <title>Communicating with Data</title> <meta name="author" content="Emi Tanaka"> <link rel="stylesheet" href="css/styles.css"> </head> <body> <!--This section contains what you want to display on your web page.--> <h1>I'm a first level header</h1> <p>This is a paragraph.</p> </body> </html>
<html> <!--This is a comment and ignored by web client.--> <head> <!--This section contains web page metadata.--> <title>Communicating with Data</title> <meta name="author" content="Emi Tanaka"> <link rel="stylesheet" href="css/styles.css"> </head> <body> <!--This section contains what you want to display on your web page.--> <h1>I'm a first level header</h1> <p>This is a paragraph.</p> </body> </html>
<html> <!--This is a comment and ignored by web client.--> <head> <!--This section contains web page metadata.--> <title>Communicating with Data</title> <meta name="author" content="Emi Tanaka"> <link rel="stylesheet" href="css/styles.css"> </head> <body> <!--This section contains what you want to display on your web page.--> <h1>I'm a first level header</h1> <p>This is a paragraph.</p> </body> </html>
Author content
The breakdown of this HTML syntax:
start tag: | <span style=βcolor:blue;β>Author content</span> |
end tag: | <span style=βcolor:blue;β>Author content</span> |
content: | <span style=βcolor:blue;β>Author content</span> |
element name: | <span style=βcolor:blue;β>Author content</span> |
attribute: | <span style=βcolor:blue;β>Author content</span> |
attribute name: | <span style=βcolor:blue;β>Author content</span> |
attribute value: | <span style=βcolor:blue;β>Author content</span> |
block element: | <div>content</div> |
inline element: | <span>content</span> |
paragraph: | <p>content</p> |
header level 1: | <h1>content</h1> |
header level 2: | <h2>content</h2> (note: only up to 6 levels) |
italic: | <i>content</i> |
emphasised text: | <em>content</em> |
bold: | <b>content</b> |
strong importance: | <strong>content</strong> |
link: | <a href=βhttps://cwd.numbat.space/β>content</a> |
insert new line: | <br> |
unordered list: |
<ul> <li>item 1</li> <li>item 2</li> </ul> |
How these are rendered to the browser depends on the browser default style values, style attribute or CSSβ¦
.css
and styles also XHTML, plain XML, SVG and XUL.style
attribute inside HTML start tag:<link>
element:<style>
element:The breakdown of the CSS syntax:
selector: | h1 { color: blue; } |
property: | h1 { color: blue; } |
property name: | h1 { color: blue; } |
property value: | h1 { color: blue; } |
<div> Sample text </div>
background color: | div { background-color: yellow; } |
Sample text
|
text color: | div { color: purple; } |
Sample text
|
border: | div { border: 1px dashed brown; } |
Sample text
|
left border only: | div { border-left: 10px solid pink; } |
Sample text
|
text size: | div { font-size: 10pt; } |
Sample text
|
padding: |
div { background-color: yellow; βββ padding: 10px; } |
Sample text
|
margin: |
div { background-color: yellow; βββ margin: 10px; } |
Sample text
|
horizontally center text: |
div { background-color: yellow; βββ padding-top: 20px; βββ text-align: center; } |
Sample text
|
font family: | div { font-family: Marker Felt, times; } |
Sample text
|
strike: | div { text-decoration: line-through; } |
Sample text
|
underline: | div { text-decoration: underline; } |
Sample text
|
opacity: | div { opacity: 0.3 } |
Sample text
|
*
|
selects all elements | |
div
|
selects all <div> elements | |
div, p
|
selects all <div> and <p> elements | |
div p
|
selects all <p> within <div> | |
div > p
|
selects all <p> one level deep in <div> | |
div + p
|
selects all <p> immediately after a <div> | |
div ~ p
|
selects all <p> preceded by a <div> | |
.classname
|
selects all elements with the attribute class=βclassnameβ. | |
.c1.c2
|
selects all elements with both c1 and c2 within its class attribute. | |
.c1 .c2
|
selects all elements with class c2 that is a descendant of an element with class c1. | |
#idname
|
selects all elements with the attribute id=βidnameβ. |
<script>
element:src
attribute to refer to the external file:css
engine:styles.css
, that you define the styles, then most HTML outputs will support this with YAML argument css
--- output: html_document: css: ["styles.css"] ---
--- output: html_document: css: ["styles.css"] ---
or say
js
engine:which inserts:
If you need to insert at a specific location within the document then you can use includes
:
---
output:
html_document:
includes:
in_header: ["header.html"]
before_body: ["before_body.html"]
after_body: ["after_body.html"]
---
where header.html
, before_body.html
, after_body.html
includes the JS code, e.g.
Warning
Different clients may work differently! E.g. Internet Explorer and Chrome may render the same web page differently.
https://developer.mozilla.org/
You can play at https://htmltidy.net/
HTML Cheatsheet https://htmlcheatsheet.com/
CSS Cheatsheet https://htmlcheatsheet.com/css/
JS Cheatsheet https://htmlcheatsheet.com/js/
Below GIF shows interactive use of Inspect Element1 available from the menu in most web browsers when you right click on the web page2:
Λ
Summary
ETC5523 Week 2