Lecturer: Michael Lydeamore
Department of Econometrics and Business Statistics
Aim
Why
A web page consists of:
From here this all got too confusing and so now we have “living standards”
.html
.simple-example.html
<html>
<body>
<h1>ETC5523: Communicating with Data</h1>
<h2>Lecturer</h2>
<ul>
<li>Michael Lydeamore (Chief Examiner)</li>
</ul>
<h2>Tutors</h2>
<ul>
<li>Janith Wanniarachchi</li>
<li>Cynthia Huang</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>
<span style="color:blue;">Author content</span>
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> |
<img height="200px" src="https://tinyurl.com/rlogo-pic">
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:<h1 style="color:blue;">Blue Header</h1>
<link>
element:<link rel="stylesheet" href="styles.css">
<style>
element:<style type="text/css"> h1 { color: blue; } </style>
<style type="text/css">
h1 { color: blue; }
</style>
<h1>This is a header</h1>
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:<script>
document.getElementById("p1").innerHTML = "content";
</script>
src
attribute to refer to the external file:<script src="myjava.js"></script>
css
engine:<style type="text/css">
h1 { color: red; }
</style>
styles.css
, that you define the styles, then most HTML outputs will support this with YAML argument css
js
engine:which inserts:
<script type="text/javascript">
document.getElementById("p1").innerHTML = "content";
</script>
If you need to insert at a specific location within the document then you can use includes
:
---
format:
html:
includes-in-header: "header.html"
include-before-body: "before_body.html"
include-after-body: "after_body.html"
---
where header.html
, before_body.html
, after_body.html
includes the JS code, e.g.
<script src="myjava.js"></script>
<script type="text/javascript">
document.getElementById("p1").innerHTML = "content";
</script>
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 7