Lecturer: Emi Tanaka
Department of Econometrics and Business Statistics
A web page consists of:
.html
.simple-example.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
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.
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:
˜
ETC5523 Week 2