Stage 2 – HTML continued
This stage will look at the text formatting abilities of HTML. The basic text tags are:
- Headings
- Spans (rows of text with particular styles)
- Paragraphs
- Lists
- Tables
Headings
Text was typed into TextEdit and saved as a headings.html file to see how it looked as a web page. Below are screen grabs showing the creation of the TextEdit file and also the result as a web page




So the result is a webpage showing 5 different sizes that ‘Headings’ can take from h1 to h5 where h1 is the biggest and h5 is the smallest.
Spans
Spans are lengths of text, and give us the opportunity to introduce styles. Styles can be included in the HTML, as we will do here, or separated into a stylesheet file (CSS).
The file was copied into TextEdit and the results are shown below.




What’s important to note here is that the American spelling is used for ‘color’.
The span has applied the following text in red ‘Text with a style applied’.
My concern is why the word doesn’t is displayed incorrectly as doesn’t
For the time being I am going to amend the text to read does not and then read up on the issue online.


Solution has been reached to the problem but will be looked into again.
Previous Problem ressolved
The problem with apostrophe’s has been rectified, I went back to double check the preference settings in textedit (specifically the check boxes in the ‘options’ section) and then I tested the spans.html file again.



Paragraphs
Note that the HTML in the spans.html file didn’t separate the second sentence from the first <span> sentence, even though they appear separate in the code.
We need to do this specifically with a paragraph <p> tag. So the Spans.html code was altered to create the following file ‘testparagraphs.html’


As you can see the doesn’t appears correctly and also the addition of the tags <p> and </p> have created a separate paragraph of text.
The code has been altered again to create the file ‘testparagraphs2.html’

Looking at the coding for ‘testparagraphs2.html’, I would assume that the second paragraph will now have changed from the black colour to green. This means that paragraph styles can also change colour and it doesn’t need the spans style.

Exactly as predicted.
In the next exercise we are creating a file ‘testparagraphs3.html’ in which we are being introduced to the line break tag <br> (which doesn’t need a closing tag) and the inline style tag to make part of the test bold <b>…</b>


So the line break tag <br> seems to be the same as hitting the return key in microsoft word which would start the text on the next line but maintaining the same paragraph. In the above screen grab the text ‘Regular text, such as this, doesn’t need a tag.’ has been affected by the line break and sent to the next line.
Also, the inline style tag <b> has been applied in the above screen grab to make the text ‘such as this’ appear bold.
Lists
HTML has a built-in ability to produce lists with a few simple tags. There are three list types in HTML:
- Unordered lists (with bullet points) <ul> for the list and <li> for list items
- Ordered lists (with numbers or letters) <ol> and <li>
- Description lists (with headings) <dl>, <dd> and <dt>
In the following exercise we will create ‘test lists.html’ and see what the results are for <ul> and <li> tags


Problem
As you can see from the above web page screen grab that a list is created will bulletpoints but the appearance of the symbol ‘Â’ appears an an error.
I decided to google search ‘what is the code to remove this symbol  in html’ which took me and the following website seemed to have the answer
http://stackoverflow.com/questions/17493601/what-is-the-code-to-remove-this-symbol-Â-in-html


So from this tip I assume that the code <head> should be replaced with the code <meta charset=”UTF-8″>. I wasn’t sure whether I should keep the word head or not but I thought I would try without the word head as a first attempt.
I called the file ‘testlistsv2.html’


As you can see from the above screen grabs the code was a success and removed the errors.
The bullets are dark circles but this type of bullet can be altered by using a style. The next exercise shows us how to change the style of the bullets. I’ve called the file ‘testlistsv3.html’.


As you can see from the screen grab of the webpage above the unordered list has different bullet points with the addition of the code <ul style=”list-style-type:circle”>
I decided to randomly try replacing the word circle with square, triangle and star. The only successful outcome was square which can be seen below in the file ‘testlistsv4.html’.


A full description of list types is given on the following website link:
http://www.w3schools.com/html/html_lists.asp
This website is perfect for testing out problems very quickly and would have saved me time had I used it with the problems encountered so far.
It has a great function where the screen is split with the coding on the left and the result on the right of the same screen so very quick and practical to work with.
Screen grab below shows my ‘testlistsv4.html’ on their website and the ease with with the results of the coding can be seen on the same page as a split screen.

Tables
For a long time, tables were the only way to get any kind of control over the positioning of elements in an HTML page. They have now largely been superseded by other tags (divs), which we will look at in more depth, but tables are still useful in some situations.
Exercise 1
A series of codes were used to create the TextEdit file ‘testtable1.html’.


The result was a table of 2 columns with 2 rows but no border.
<table> indicates the table as a whole.
<tr> is a row of cells.
<td> is an individual cell.
A column isn’t usually specified as such, but naturally occurs when each row has the same number of cells.
Exercise 2
To extend the code to make a table with 3 rows of 3 columns each. I decided I wanted to be adventurous and try to make the text in the first row ‘Column 1’ ‘Column 2’ and ‘Column 3’.
Then, to have Item 1 and Item 2 in each column.
Below are the results of my first trial at this exercise with files ‘testtable2.html’


My test was a success but it would look better if the columns were aligned to the centre. I researched the w3schools website but found out that the align attribute is no longer supported by most browsers.
Exercise 3
Now add this to the table tag:
<table border=”1″>
I had to check on w3schools.com to make sure I was putting the above code in the correct place and I assumed it to replace line 7 <table> with <table border=”1″>


<table border=”1″> has placed a border around each row and each column of the table.
I tested with <table border=”10″> to see what happens and the higher the number the thicker the border around the table. Look at the screen grab below of a test on http://www.w3schools.com
<table border=”1″> is another way of adding a style to an element, specifying the attribute directly rather than with “style=” as we did previously.
It is much easier to get full control over styles using CSS, so that is what we will generally do in future.
Exercise 3
A challenge:
Make a 2 row table with 2 cells in the top row and 3 cells in the bottom row, using the attribute colspan=”2” in one of the <tr> tags.
Firstly, I researched what ‘colspan’ means and the defintion found was COLSPAN (“how many across”) indicates how many columns across a cell should take up.
So the idea is for the first row to have 2 cells where the colspan of the second cell will be 2 cells across.
My first attempt at ‘testable4.html’ resulted in a successful completion of the challenge.


However, I wanted to made the headings bold and align them centrally and also try to align the second row centrally as well. So I read up on http://www.3schools.com and used
style=”width:50%” This code was used to widen each cell
<th>…</th> This tag was used to create bold headings and this tag automatically centres the heading inside the cell
<td style=”text-align:center”> CSS was used to align the second row centrally within each cell
As you can see below quite a few trials and errors were overcome to finally achieve my version of the challenge.






Practice
For practice we were advised to visit the following website links
http://www.w3schools.com/html/html_formatting.asp
http://www.w3schools.com/html/html_lists.asp
http://www.w3schools.com/html/html_tables.asp
http://www.w3schools.com/tags/att_td_colspan.asp
and other HTML lessons from
http://www.w3schools.com/html/default.asp
Summary
There are different ways of bringing simple styles into HTML:
- style attributes within the opening tag: <span style=”color:red”>
- attributes in the tag, without the ‘style’ tag: <table border=”1″>
- inline styling tags: <b> … </b>
and different simple layout formatting techniques:
- headings
- paragraphs
- spans
- tables
- lists




















