HTML CSS JavaScript Coding Guide
HTML CSS JavaScript Coding Guide
HTML CSS JavaScript Coding Guide
Are you curious about creating websites, this course is the perfect place to
start. Learn all the core fundamentals of modern web design, covering all
the commonly used syntax for HTML and CSS. This course is designed to
get you started quickly and easily with creating web pages.
Course covers all the essentials so that you can begin quickly on your
journey to create amazing looking websites. Add JavaScript to make your
web pages come to life. Covering the core concepts of JavaScript so that
you can try the code and get familiar with what it does. Using JavaScript
you can access the HTML DOM in the browser which allows you to interact
and manipulate web page content. JavaScript creates the interactive and
dynamic content seen today in all major modern web pages.
Explore how you can start coding quickly and focus on designing your web
pages, loaded with source code and examples. Each section comes with a
PDF guide that includes useful section resources, and source code from the
lessons so that you can try the code for yourself.
CSS 22
Getting started with Code 22
Adding Styling to your HTML 23
Styling Overview 23
Colors Background and Font Color 25
Box Model Border Padding Margin 26
Text options 28
Fonts and Font Styles 29
Link States Pseudo-Classes 32
Display Properties 34
CSS Position 35
CSS Float 36
Useful CSS Properties 40
CSS Combinators 42
CSS Pseudo Elements 46
Responsive Website CSS Float 47
Responsive Website Flexbox 51
Responsive Website CSS Grid 55
JavaScript Code 58
HTML
Learn HTML - how to create an HTML file and structure your HTML code in
a modern format ready to be styled. Lessons of this section cover how
to get started with coding and creating web pages.
● Setup your Editor and create HTML files
● Debug your code
● HTML tags for page structure
● What makes up an HTML element
● What are Self closing Tags
● How to use Element Attributes
● Linking pages together with Hyperlinks
● Adding Images to your web page
● Lists and Tables for readable content
Online Code Editor - great to practice code without a need for download
of applications
https://codepen.io/pen/
Code Editor - write code with a code editor as it can help structure and
suggest tags for code.
https://code.visualstudio.com/
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
Hello
HTML Element
Anatomy of an HTML element - opening tag, content, element, closing tag
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<div>
<p>Hello World!</p>
<div>Welcome to my site.</div>
<div>Welcome to my site.</div>
<p>My name is Laurence.</p>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<div>
<h1>Hello World!</h1>
<div>Welcome to my site.</div>
<div>Welcome to my site.</div>
<p>My name is <span>Laurence</span>
<span></span>Svekis</span>.</p>
</div>
<h2>Heading 2</h2>
<h4>Heading 4</h4>
<h6>Heading 6</h6>
<!-- Add another div here -->
<!--
<div>
Content
</div>
-->
</body>
</html>
Element Attributes
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My Page</title>
<style>
.blue{
color:blue;
}
.red{
color:red;
}
</style>
</head>
<body>
<p id="myID">
Hello<br>World
</p>
<div>
<h1>Hello World!</h1>
<div style="color:blue;">Welcome to my site.</div>
<div style="color:red">Welcome to my site.</div>
<hr>
<p title="My Name">My name is <span>Laurence</span>
<span></span>Svekis</span>.</p>
</div>
</div>
HTML Table
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My Page</title>
<style>
table, th, td{
border:1px solid black;
border-collapse:collapse;
padding:5px;
}
Semantic Elements
<!DOCTYPE html>
<html>
<head><title>My Website</title></head>
<body>
<header class="header">Header</header>
<nav class="navbar">Nav</nav>
<section class="content">
<section>Main</section>
<aside>Side Bar Content</aside>
<article>More details</article>
</section>
<footer class="footer">Footer</footer>
</body>
</html>
WebPage HTML
<!DOCTYPE html>
1.
4 - Fill Out the REPO details
9 - enable the github page and view the page at the web URL
Online Code Editor - great to practice code without a need for download
of applications
https://codepen.io/pen/
Styling Overview
● Comments in Code /* */
● find help with CSS
● Google Fonts
● https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_
the_web/CSS_basics
● https://fonts.google.com/
/*
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Val
ues_and_units
.blue {
background-color: rgba(255,0,255,0.5);
color:white;
}
.red{
background-color:#ff00ff80;
color:rgb(255,255,255);
}
.h6{
div {
border-style: solid;
#bottom {
color:red;
border:1px solid black;
padding:20px;
margin-top:50px;
line-height: 1;
text-align: left;
text-transform: uppercase;
text-indent: 30px;
letter-spacing:5px;
word-spacing: 20px;
body{
font-family: 'Fira Sans', sans-serif;
font-style: italic;
font-weight: bold;
font-variant: small-caps;
font-size:100%;
}
h1{
font-size: 12vw;
color:blue;
text-align: center;
}
.h6{
color:aquamarine;
font: italic bold 1.5em Arial;
background-color:black;
}
#bottom{
font-size: 1.5em;
}
.bigger{
color:red;
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Servics</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
a:link{
color:red;
}
a:visited{
color:chartreuse;
}
a:hover{
color:darkblue;
text-decoration: none;
}
a:active{
color:darkmagenta;
}
h1{
background-color:black;
color:white;
}
h1:hover{
background-color:darkorange;
}
h1:active{
background-color:red;
}
Display Properties
li {
background-color:black;
display:inline-block;
padding:10px;
list-style: none;
}
ul {
margin:0;
padding:0;
}
a{
color:white;
}
#bottom {
display:block;
}
span{
visibility:visible;
<nav>
<ul>
<li><a href="#1">Home</a></li>
<li><a href="#2">Servics</a></li>
<li><a href="#3">About</a></li>
<li><a href="#4">Contact</a></li>
</ul>
</nav>
CSS Position
● Position : static relative fixed absolute sticky
header{
background-color:rgba(255,0,0,0.5);
padding:10px;
position:static;
}
header{
position:relative;
}
header{
header{
position:absolute;
top:10px;
left:10px;
width:200px;
height:200px;
}
header{
position:sticky;
}
CSS Float
li {
float:right;
}
li {
float:left;
}
ul{
border:1px solid black;
padding:30px;
}
article{
width:80%;
background:lightpink;
float:left;
}
aside{
width:20%;
background:lightblue;
float:left;
● Max Width
● Overflow
● Z-index
● outline
header {
outline-color: magenta;
outline-width: 2px;
outline-style: solid;
border: 5px solid yellow;
max-width:800px;
margin:auto;
}
ul{
z-index: -1;
position:fixed;
}
article{
background:rgba(255,0,0,0.5);
z-index: 5;
}
aside{
background:blue;
z-index: 3;
}
footer{
font-size: 2em;
height:20px;
width:70%;
background:black;
color:white;
overflow:auto;
margin-bottom:100px;
}
a[href="#2"] {
color:red;
background-color: moccasin;
}
h1,h2,h4,h6{
padding:10px;
border:5px dotted pink;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style11.css">
<title>My Page</title>
</head>
article::before{
content:'NEW content';
}
article::after{
content:'After';
}
<!DOCTYPE html>
<html>
<head>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="site1.css">
<title>My Page</title>
</head>
<body>
<header class="header">
<h1>Welcome to my Website</h1>
</header>
<div class="main">
<aside class="col">
<ul>
<li><a href="#1">Home</a></li>
<li><a href="#2">Servics</a></li>
<li><a href="#3">About</a></li>
@import
url('https://fonts.googleapis.com/css2?family=Indie+Flower&display=s
wap');
*{
box-sizing: border-box;
}
.header {
background-color: skyblue;
text-align: center;
padding: 20px;
text-transform: uppercase;
}
ul {
display: flex;
flex-direction: row;
margin: 0;
padding: 0;
}
li {
list-style-type: none;
padding: 5px;
li:hover {
background-color: steelblue;
}
li a {
text-decoration: none;
.main {
display: flex;
flex-direction: column;
}
.main article {
flex: 3;
padding: 10px;
}
.main aside {
flex: 1;
text-align: center;
}
.col {
border: 1px solid black;
}
.footer {
@media (min-width:640px) {
body {
background-color: #ddd;
}
.main {
flex-direction: row;
}
ul {
flex-direction: column;
}
li {
padding: 10px;
}
}
*{
box-sizing: border-box;
}
body{
.header , .footer{
background-color: black;
color:white;
text-align: center;
padding:10px;
}
.main{
display:grid;
grid-template-areas:
'cola colb colb colc';
}
ul {
margin:0px;
padding:0px;
}
li{
list-style-type: none;
}
li a{
text-decoration: none;
display:block;
background-color:blue;
color:white;
text-align: center;
@media (max-width:640px){
.main{
grid-template-areas:
'cola'
'colb'
'colc';
}
}
console.log('hello');
alert('hello');
alert('world');
console.log('world');
JavaScript Variables
● Variables Let and Const
console.log('ready');
// No space in the variable name
// $_0-9a-zA-Z
// Case sensitive
// Can't begin with 0-9
// can't use reserved JavaScript Keyword
/// var used prior to let and const introduction
let myName = 'Laurence Svekis';
console.log(myName);
myName = 'Laurence Smith';
if(true){
const myName1 = 'Laurence 2';
console.log(myName1);
console.log(myName);
}
JavaScript DataTypes
● Data Types
let val1;
val = null;
let a,b,c,d;
console.log(myName);
console.log(val);
console.log(typeof(b));
//console.log(typeof myArr);
const myObj = {
first:'string',
val : 100,
boo : true
};
//console.log(myObj);
//console.log(typeof myObj);
//console.log(myObj['boo']);
//console.log(myObj.boo);
const myName = {
first : 'Laurence',
last : 'Svekis',
arr : [1,2,3,4],
myObj : {
one : 'one',
two : 'two'
}
}
console.log(myName.myObj.one);
console.log(myName['myObj']['one']);
JavaScript Operators
let val = 1;
val = val * 5;
val = val - 3;
val = val / 2;
val = val + 10 + 10 + 30;
val = 51 % 10;
val++;
val--;
val -= 3;
val += 10;
val *= 5;
● Functions
● function expressions vs function declarations
function declarations
● global scope and make it available throughout your code
function expression
● function expression can be used as an IIFE
//console.log(myFun2());
//myFun2();
///myFun2();
const val2 = myFun2();
//console.log(val);
let a = 50;
let b = 94;
let test = a + ' + ' + b + ' = '+ adder(a,b);
console.log(test);
console.log(a + ' + ' + b + ' = '+ adder(a,b));
function adder(a,b){
//let val = a + b;
console.log(val);
return a + b * 1;
console.log('message');
}
JavaScript Conditions
● Conditions
let a = 40;
let b = 10;
checker(50,100);
checker(70,10);
checker(80,100);
function checker(a,b){
let res;
if ( a > b) {
res = (a + ' is bigger than ' + b);
} else {
res = (a + ' was not bigger than ' + b);
}
console.log(res);
}
//console.log(test.length);
for(let x=0 ; x < test.length ; x++){
//console.log(test[x]);
}
test.forEach(function(val,index,array){
console.log(val + ' ' + index);
});
const myObj = {
first : 'Laurence',
last : 'Svekis',
one : 1,
two : 2,
three : 3
}
console.dir(document);
let myDOM = {
URL : "My URL",
children : [
{html : {
"body" : "Content"
}}
]
}
Element Selection
● Element Selection
● Multiple Elements selection
const ele1 = document.getElementById('myEle');
console.log(ele1);
console.log(ele1.textContent);
ele1.textContent = 'Laurence Svekis';
console.log(ele4.textContent);
const myObj1 = {
first : "Laurence"
}
const my1 = myObj1;
const my2 = myObj1;
my1.first = "Svekis";
console.log(my2);
<!doctype html>
<html>
<head>
<title>JavaScript</title>
<style>
outputs.forEach(function(el){
if(el.tagName != 'H1'){
el.innerHTML = html;
}
})
document.write(html);
ele1.setAttribute('style','');
<!doctype html>
<html>
<head>
<title>JavaScript</title>
<style>
.box{
background-color:blueviolet;
color:white;
padding:10px;
margin:10px;
}
</style>
</head>
<body>
<h1 class="output">Hello DOM</h1>
● Input Values
first.value = 'Laurence';
last.value = 'Svekis';
chk.checked = true;
btn.addEventListener('click',btnClicked);
function btnClicked(e){
console.log(e.target.id);
e.target.id = 'NEW' + counter;
counter++;
console.log('clicked '+counter);
e.target.textContent = 'Clicked ('+counter+')';
e.target.classList.toggle('box');
}
const h1 = document.querySelector('h1');
h1.onclick = btnClicked;
<!doctype html>
<html>
<head>
<title>JavaScript</title>
<style>
.box{
background-color:blueviolet;
color:white;
padding:10px;
margin:10px;
}
</style>
</head>
<body>
<h1 id="h1" class="output" >Hello DOM</h1>
<div class="output">JavaScript</div>
<div id="myEle">Hello World</div>
<input name="first">
<input name="last">
<input type="checkbox">
<button>Click Me</button>
<div>Hello World 2</div>
<div class="output">JavaScript</div>
<script src="dom6.js"></script>
</body>
</html>
holder.addEventListener('mouseover',(e)=>{
holder.style.background = 'red';
//holder.classList.toggle('box');
function output(a,e){
console.log(a);
}
function adder(e){
const el = e.target;
el.removeEventListener('click',adder);
el.style.color = '#ddd';
console.log('clicked');
}
inputs.forEach((el)=>{
el.addEventListener('change',updater);
el.addEventListener('focus',(e)=>{
console.log(el.textContent);
el.style.background ='red';
el.style.color = 'white';
function updater(e){
const val = e.target.value;
h1.textContent = val;
}
h1.addEventListener('click',(temp,{once:true})
function temp()
console.log('test');
h1.style.color = 'red';
}
document.body.onload = ()=>{
console.log('body loaded');
}
document.addEventListener('DOMContentLoaded',(e)=>{
document.addEventListener('keydown',(e)=>{
console.log(e.key);
h1.textContent += e.key;
})
document.addEventListener('keyup',(e)=>{
console.log(e.key);
})
console.dir(window);
//window.alert('hello');
window.onresize = ()=>{
h1.innerText = window.innerHeight + ' ' + window.innerWidth;
}
first.value = "Laurence";
btn.addEventListener('click',(e)=>{
//holder.innerHTML = "";
console.log(first.value);
div.textContent = first.value;
console.log(div);
const div1 = document.createElement('div');
holder.append(div1);
div1.textContent = "HELLO";
holder.append(div);
holder.prepend(div);
div.style.color = 'red';
})
function adder(){
counter++;
console.log('clicked');
const newEle = createEle('div',output,'hi '+counter);
console.log(newEle);
newEle.style.background = 'blue';
}
function createEle(elType,parent,html){
Element Movement
document.addEventListener('keydown',(e)=>{
console.log(e.key);
if(e.key == 'ArrowLeft'){
ele.x -= 50;
}
if(e.key == 'ArrowRight'){
ele.x += 50;
}
if(e.key == 'ArrowUp'){
ele.y -= 50;
}
if(e.key == 'ArrowDown'){
Element Animation
https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnima
tionFrame
<!doctype html>
<html>
<head>
<title>JavaScript</title>
</head>
<body>
<script src="dom11.js"></script>
</body>
</html>
function ran(){
return Math.floor(Math.random()*255)
}
output.addEventListener('click',(e)=>{
const col = 'rgb('+ran()+','+ran()+','+ran()+')';
output.style.background = col;
console.log(col);
})
const player = {
x : 0,
y : 0,
speed : 10,
ani : window.requestAnimationFrame(moveMe)
}
const keyz = {
ArrowDown : false,
ArrowUp : false,
ArrowRight : false,
ArrowLeft : false
}
window.addEventListener('keydown',(e)=>{
keyz[e.code] = true;
function moveMe(){
if(keyz.ArrowRight){player.x += player.speed}
if(keyz.ArrowLeft){player.x -= player.speed}
if(keyz.ArrowUp){player.y -= player.speed}
if(keyz.ArrowDown){player.y += player.speed}
output.style.left = player.x + 'px';
output.style.top = player.y + 'px';
player.ani = window.requestAnimationFrame(moveMe);
}