- This image is pure CSS.
By Chen Hui Jing / @hj_chen
http://bit.ly/tl-ws1-2018
The process of building websites
A clear mind
In most circumstances, we do development on our local machines, but given that setting up for development deserves its own workshop, we'll be using online tools for the second part of the workshop later.
The entire network of networks that connect all the world's devices to each other
Enter a URL in the address bar
Browser sends request to server and server locates the requested file
Server returns the file to the browser which displays it
A link on a web page is a pre-entered URL. Clicking the link sends a request to the server.
The server sends the requested file back to the browser, which replaces the current page with the new file.
Absolute paths ask for a file from a specific location, which includes the protocol and server.
<a href="http://www.unicorn.com/gallery.html">Gallery<a>
Relative paths ask for a file without specifying a server.
<a href="gallery.html">Gallery<a>
The browser will hence assume you're referring to the same server as the page you're on.
<p>This is an example of a paragraph element</p>
<!DOCTYPE html>
<html>
<head>
<title>Example page</title>
</head>
<body>
<h1>Hello world</h1>
</body>
</html>
<!DOCTYPE html>
<html>
tag<html>
element<html lang="en">
// HTML code for web page
</html>
<head>
element<head>
<meta charset="utf-8">
<title>Your site title</title>
<meta name="description" content="A short description of your website">
<meta name="author" content="Your name">
<link rel="stylesheet" href="css/styles.css?v=1.0">
</head>
<body>
element<body>
<header>
<img src="img/logo.png" alt="Site logo">
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
<main>
<h1>Page header</h1>
<p>Some content in a paragraph. Brownie tiramisu toffee sweet roll sesame snaps halvah. Fruitcake donut pie ice cream jujubes danish dragée. Bear claw jelly dessert lemon drops bonbon donut. Sugar plum sugar plum candy canes ice cream powder tootsie roll sweet. Sugar plum biscuit macaroon fruitcake cookie cupcake jelly-o cupcake. </p>
<main>
</body>
<body>
element on a web page<address>
<article>
<footer>
<header>
<h1>
<h2>
<h3>
<h4>
<h5>
<h6>
<hgroup>
<nav>
<section>
<dd>
<div>
<dl>
<dt>
<figcaption>
<figure>
<hr>
<li>
<main>
<ol>
<p>
<pre>
<ul>
<caption>
<col>
<colgroup>
<table>
<tbody>
<td>
<tfoot>
<th>
<thead>
<tr>
<button>
<datalist>
<fieldset>
<form>
<input>
<keygen>
<label>
<legend>
<meter>
<optgroup>
<option>
<output>
<progress>
<select>
<details>
<dialog>
<menu>
<menuitem>
<summary>
<abbr>
<b>
<bdi>
<bdo>
<br>
<cite>
<code>
<data>
<dfn>
<em>
<i>
<kbd>
<mark>
<q>
<rp>
<rt>
<rtc>
<ruby>
<s>
<samp>
<small>
<span>
<strong>
<sub>
<sup>
<time>
<u>
<var>
<wbr>
<area>
<audio>
<map>
<track>
<video>
<embed>
<object>
<param>
<source>
<canvas>
<noscript>
<script>
<del>
<ins>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
<meta name="description" content="A short description of your website">
<meta name="author" content="Your name">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<!-- page content -->
<script src="script.js"></script>
</body>
</html>
Block-level elements take up the entire width of the container.
A rainbow is a meteorological phenomenon that is caused by reflection, refraction and dispersion of light in water droplets resulting in a spectrum of light appearing in the sky.
The block-level tags shown in this example are h1
, h2
, p
, ul
and li
.
You can refer to the full list of block-level elements here.
If an element is NOT block-level, it is inline.
Accordingly, the Munsell colour system (a 20th-century system for numerically describing colours, based on equal steps for human visual perception) distinguishes 100 hues.
<p class="tl-example-4">Accordingly, <a href="https://en.wikipedia.org/wiki/Munsell_color_system">the Munsell colour system</a> (a 20th-century system for numerically describing colours, based on equal steps for human visual perception) distinguishes 100 hues.</p>
Commonly used inline-level tags include a
, input
, label
, img
and so on.
Full list of inline-level elements available here.
selector {
property1: value;
property2: value;
property3: value;
}
p {}
<div class="example">
.example {}
<div id="example">
#example {}
Used to select tags that are children of other tags
<ul>
<li>4 large eggs</li>
<li>1/4 cup milk</li>
<li>2 tsp. butter</li>
</ul>
<ol>
<li>BEAT eggs, milk, salt and pepper in medium bowl until blended.</li>
<li>HEAT butter in large nonstick skillet over medium heat until hot. POUR IN egg mixture. As eggs begin to set, GENTLY PULL the eggs across the pan with a spatula, forming large soft curds.</li>
<li>CONTINUE cooking – pulling, lifting and folding eggs – until thickened and no visible liquid egg remains. Do not stir constantly. REMOVE from heat. SERVE immediately.</li>
</ol>
ul li {
color: green;
}
Selector list is read from right-to-left, with the left-most being the parent.
Applies to selectors when certain conditions occur
a {
/* removes underlines from
all text links */
text-decoration: none;
}
a:hover {
/* adds an underline and makes
the font green when hovered */
text-decoration: underline;
color: green;
}
The model is made up of four boxes, from inside to outside:
Margin controls the space between elements.
h2 {
margin: 5px 0 5px 0;
}
A rainbow is a meteorological phenomenon that is caused by reflection, refraction and dispersion of light.
h2 {
margin: 20px 0 20px 0;
}
A rainbow is a meteorological phenomenon that is caused by reflection, refraction and dispersion of light.
Padding controls the size of the box without adjusting the size of the content within it.
h2 {
padding: 0;
}
A rainbow is a meteorological phenomenon that is caused by reflection, refraction and dispersion of light.
h2 {
padding: 20px 0 20px 0;
}
A rainbow is a meteorological phenomenon that is caused by reflection, refraction and dispersion of light.
Browsers will pick up your CSS if they are between a <style>
tags which is a child of the <head>
tag.
<!DOCTYPE html>
<html lang="en">
<head>
<style type="text/css">
h1 {
font-size: 2rem;
}
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
color: darkred;
}
</style>
</head>
As your site grows, you'll have many more styles, so it's better to move them all into a separate file.
<!DOCTYPE html>
<html lang="en">
<head>
<link type="text/css" rel="stylesheet" href="main.css">
</head>
In this example, we are using main.css
but you can name the file anything. This file will hold all your CSS and be linked in the <head>
of every page.
Inline styles
IDs
Classes, attributes and pseudo-classes
Elements and pseudo-elements
ul {
// CSS properties
}
0, 0, 0, 1
.class-1 .class-2 p {
// CSS properties
}
0, 0, 2, 1
#id-1 .class-3 div {
// CSS properties
}
0, 1, 1, 1
Content images are created using the <img>
tag
<img src="path/to/image" alt="Description of the image">
<src>
attribute to tell the browser where to find the image file<alt>
attribute which describes the image or its purposeBackground images are set via CSS
There are several properties related to backgrounds:
background-image: none
background-position: 0% 0%
background-size: auto auto
background-repeat: repeat
background-origin: padding-box
background-clip: border-box
background-attachment: scroll
background-color: transparent
background
is one of many CSS properties that can be written in shorthand.
background-image
can use relative or absolute paths
div {
background-color: #170104;
background-image: url('img/background.jpg');
}
It's advisable to set a background-color
as a fallback for the background image
This is a div
with a background image
This is used to set the position of the image
div {
background-color: #170104;
background-image: url('img/background.jpg');
background-position: center center;
}
Position has been set to center center
div {
background-color: #170104;
background-image: url('img/background.jpg');
background-position: left bottom;
}
Position has been set to left bottom
Used for tiling patterned backgrounds
Takes the following values:
repeat-x
: tiles the image horizontallyrepeat-y
: tiles the image verticallyno-repeat
: don't tile or repeat anythingdiv {
background-color: #EBEBEB;
background-image: url('img/sativa.jpg');
background-repeat: repeat;
}
Typography is, quite simply, the art and technique of arranging type.
Don't go crazy with the number of fonts used. Usually 2 is enough.
Serve the font files yourself using @font-face
or use a hosted service, like Google Fonts, using @import
@import url(https://fonts.googleapis.com/css?family=Fjalla+One|Average);
body {
font-family: "Average", serif;
}
h1 {
font-family: "Fjalla One", sans-serif;
}
Every modern browser has a powerful suite of developer tools.
Your computer's personal manager
How computers store information
>_
Git is a version control system
Repository: A place that stores all your project files
Commit: Used to take a "snapshot" of the state of your project
Branch: Used to develop features without disrupting the main code base
Fork: A copy of a repository, allows you to freely experiment with changes without affecting the original project.
Make sure you're in your project directory, otherwise the following commands will not work.
Stage the files you've been working on
git add .
Write a sensible commit message
git commit -m "Add styling to Guess the Number app"
Push your changes to the remote repository
git push origin master
Our problems with websites are self-created
Satirical but true example"The control which designers know in the print medium, and often desire in the web medium, is simply a function of the limitation of the printed page."
- John Allsop, A Dao of Web Design (2000)
Tell the browser to display the site’s content in a particular way when certain conditions are true.
Basic syntax as follows:
@media <media-type> (<media-feature>);
screen
, print
width
, height
.o-flex3__item {
flex: 0 0 100%
}
@media all and (min-width: 30em) and (max-width: 47.9375em) {
.o-flex3__item {
flex: 0 0 49.15254%
}
}
@media all and (min-width: 48em) {
.o-flex3__item {
flex: 0 0 32.20339%
}
}
Visit Web Accessibility Initiative (WAI) to understand more about this important aspect of the web
Domain names map to your server's IP address
Provides a human-readable name for ypur site
Top-level domains, e.g. .com
, .io
, .org
, .edu
Register domain names with a domain name registrar
Upload the files onto your server, Git or FTP
Servers usually run on Linux
Type of hosting determines level of control
Must be running a HTTP server, common ones are Apache or Nginx
A place to host your application
Connects to GitHub for easier deployment
https://www.heroku.com/Font used is Edmond Sans, by James T. Edmondson