Week 2 - Tables, CSS & Fonts
Week 2 - Tables, CSS & Fonts
Sean Preston
What you’ll learn today…
1. You will be introduced to HTML Tables and CSS.
2. You will learn to utilise CSS to apply custom styles and improve the
UI of your website.
3. Learn how to implement external font libraries (and icon fonts) into
your website to improve typography.
HTML Tables
Introduction to HTML Tables
• Tables allow us to display tabular data on our website (data arranged
into rows and columns).
• Therefore, in most cases you will always want to make sure you have
the same number of <td>…</td> elements in each row.
Let’s look at some code…
<table> • Here we can see the wrapper
<tr>
<th>Name</th> <table> … </table> element.
<th>Age</th>
<th>Language</th> • All code for our table must be
</tr> kept inside these two elements.
<tr>
<td>Fred</td>
<td>30</td>
<td>English</td>
</tr>
</table>
Let’s look at some code…
<table> • Now, we’ve added two sets of
<tr>
<th>Name</th> <tr> … </tr> tags. These
<th>Age</th> represent a row in our table.
<th>Language</th>
</tr>
• In this table the first row
<tr>
contains our headings. The
<td>Fred</td>
second row contains one set of
<td>30</td>
data.
<td>English</td>
</tr>
</table>
Let’s look at some code…
<table> • Now, we’ve used <th> … </th>
<tr>
<th>Name</th> tags to define our table
<th>Age</th> headers.
<th>Language</th>
</tr>
• In this case the headers are
<tr>
Name, Age and Language.
<td>Fred</td>
<td>30</td>
<td>English</td>
</tr>
</table>
Let’s look at some code…
<table> • Similar to our headers, we use
<tr>
<th>Name</th> <td> … </td> tags to define
<th>Age</th> individual pieces of data.
<th>Language</th>
</tr>
• These can also be seen as
<tr>
columns.
<td>Fred</td>
<td>30</td>
<td>English</td>
</tr>
</table>
The result…
<table>
<tr> Name Age Langauge
<th>Name</th>
<th>Age</th> Fred 30 English
<th>Language</th>
</tr>
<tr>
<td>Fred</td>
<td>30</td>
<td>English</td>
</tr>
</table>
Column and Row Spans
• There might be some cases where you want to present one cell over
multiple rows or columns.
• You could see this as being similar to the “Merge Cells” tool in MS
Word and Excel.
• For example, a table could quite possibly have two rows of headings.
Before the new HTML5 elements, these headings were completely
disconnected.
• For example, we could use CSS to change the colour of text elements
or to position an image on the right side of the page.
CSS History
• CSS 1 was first introduced in 1996.
• Less work – Normally a single CSS stylesheet is used for the entire
website. Therefore, we only have to make the majority of style
changes once.
2. Create a new CSS document and write styles for the elements
created in step 1.
3. Attach the CSS document to the HTML page. This will apply the
styles to the page.
A note on IDs and Classes
• The two main ways to attach styles to elements on are page is to use
IDs and Classes.
• This would apply the style to all div elements on the page.
CSS Comments
• In CSS we can add comments to our code like so…
/* This is a comment */
/*
This is a comment
*/
Including CSS Styles - Inline
• We can include CSS styles in our HTML by placing them within the
HTML tags <style> … </style> tags like so…
<style>
div {
color: red;
}
</style>
Including CSS Styles – External files
• We can also include external CSS files. You would do this inside your
<head> … </head> tags. Like so….
<head>
<link rel=“stylesheet” href=“./styles.css”>
</head>
• Very rarely should you place CSS styles inside the <style>…</style>
tags.
• An external file makes development far easier as it’s likely your CSS
file will become quite large over time.
CSS Style Structure
• This is the selector.
#address {
color: red; • In this instance we’re selecting
font-family: Roboto; any element with the ID
font-size: 14px; “address”.
}
CSS Style Structure
• These are the styles being
#address { applied to the element.
color: red;
font-family: Roboto; • Color will set the text colour to
font-size: 14px; Red.
}
• Font family and font style will
stylise the typography.
Basic CSS Styles
Basic CSS Styles - Fonts
• Font-family
• Specify one or more fonts (comma separated).
• Font-size
• This is the size of the text. It can be represented using pixels (px) or use relative
values such as %, em or rem.
• It is possible to also use absolute keywords such as “small”, “medium” or “large”.
However, this is not recommended.
• Font-weight
• This is the weight applied to fonts. For example 100 is super-thin whereas 900 is
super-bold. The range of values depend upon the font being used.
Basic CSS Styles – Fonts Continued
• Font-style
• Normal, italic etc
Basic CSS Styles - Colours
• Colours can be used in a range of different styles. For example, they
can be used by the “color” style to set a text colour. Or, by
“background-color” to apply a background colour to the element.
• Background-repeat
• Allow an image to repeat on the x and y axis.
• Background-position
• We can set the position of the background image (e.g. left, center, right, top,
bottom)
Basic CSS Styles - Text
• Line-height
• Adds/removes spacing before and after each line.
• Text-indent
• Indent the first line of text.
• Text-align
• Align the text left, right, center or justify.
• Text-transform
• None, capitalize, lowercase, uppercase
Basic CSS Styles - Text
• Text-shadow
• Adds a drop shadow to text.
Basic CSS Styles - Misc
• Opacity
• Add an opacity to the element. The element still exist on the page, it just
becomes transparent.
• Visibility
• Hide an element. This is similar to opacity but when set to “hidden” the
element is actually removed from the page.
Basic CSS Styles - Display
• Block
• Makes the element full width.
• Inline
• Makes the element inline.
• None
• Hides the element.
Chrome Developer
Tools
Demonstration
External Fonts & Icon
Fonts
Including Custom Fonts
• There are many ways in which we can add fonts to the websites we
create.
• We can add them manually to our websites file structure (and we’ll
look at this later in the module). This is ideal for custom fonts.
• Some fonts however don’t provide this service and you need to
download them and include them in a more traditional way.
Google Fonts
• Large libraries of fonts now exist that we can use in our websites. No
longer are we restricted to system fonts (which often look a little
boring!).
• But, we can actually use fonts as a great way of storing icons. Because
they’re a font we can use them at any size and they’re quick to load in
the users browser.
• Obviously, there are some limitations. For example, the entire icon
needs to be the same colour (in the same way that each character in a
standard font needs to be a colour).
Font Awesome
• First released on December 7th 2017, Font Awesome is an icon font
library this is … awesome!
• It allows us access to over 1,513 free icons and 5,097 pro icons. Their
pro package costs between $60 - $99 annually. However, for most
websites the free package is sufficient.
Fontello
• Fontello is an online platform that allows you to build your own icon
font.
• Fontello allows you to choose which icons you need from a range of
different icon font packages (including Font Awesome).
Activities