HTML Beginners Basics of Web Paul Gibbs
HTML Beginners Basics of Web Paul Gibbs
HTML Beginners Basics of Web Paul Gibbs
Copyright
Copyright © 2016 Paul Gibbs
All rights reserved. This book or any portion thereof may not be reproduced or used in
any manner whatsoever without the express written permission of the publisher except for
the use of brief quotations in a book review.
Email: [email protected]
Trademarks
MySQL is a trademark of Oracle Corporation and/or its affiliates. Macintosh and Mac OS
X are registered trademarks of Apple Inc. Microsoft and Windows are registered
trademarks of Microsoft Corp. Dreamweaver is a registered trademark of Adobe Systems
incorporated. The WordPress Foundation owns and oversees the trademarks for the
WordPress and WordCamp names and logos. Other product names used in this book may
be trademarks of their own respective companies. This book is not affiliated with or
endorsed by any of the products mentioned.
One of the issues that we have in the computer world is that it is very much influenced by
the US designers of software. Hence the word “color” is used instead of the British
English spelling of “colour”. In this book I use “color” throughout. I did for a while
consider using the word “color” when writing about the style attribute but use “colour”
when writing about color generally, but thought that would just confuse things. So British
English readers will have to put up with “color” for now.
Using the code examples
All the code examples with answers to the exercises may be downloaded to your computer
from the web site:
http://www.paulvgibbs.com
or:
http://www.withinweb.com/ebook
Book Version
June 2016 is the current version
Table of Contents
1 Introduction
The processing of an HTML page
A basic HTML page
The type Declaration tag
The Head tag
The Body tag
Some HTML tags
HTML 5
CSS 3
Folders and Files and Servers
Content Management Systems and HTML
Common errors that beginners make
Some useful web sites
Some HTML Editors
Summary
2 HTML Tags
TASK 1 - Creating Folders
TASK 2 – Create a new Web Page
TASK 2 - Saving the Page
TASK 3 - Inserting headings
TASK 4 - Inserting and formatting the text
TASK 5 - Formatting your text - The style attribute
TASK 6 - The bold <strong>and italic <i>tags
TASK 7 - Copying files into folders and - inserting an image
TASK 8 - The image tag
TASK 9 - Borders and aligning images
TASK 10 - Adding a Horizontal line
TASK 11 - Other formatting
TASK 12 - Links to other pages
TASK 13 - Anchor Links to places on the same page
TASK 14 - Email links
TASK 15 - HTML Special Characters
TASK 16 - Lists and bullets
TASK 17 - Colors in html
TASK 18 - Page validation
Debugging in the browser
Using the inbuilt developer tools in web browsers
Emulating different devices using Google Chrome
Firefox debugger
XHTML validate the web page
Use Dreamweaver to check the document
Google Chrome PageSpeed utility
Some Standard HTML Tags
Summary
5 Further Styles
Style Definition Summary
[1] Built in Tags (selectors)
[2] Classes
[3] ids
Style Exercises
TASK 1 - Set the page to a defined font and size
STYLES
BODY TEXT
TASK 2 - Modify an h1 tag
TASK 3 - Modify a paragraph tag
TASK 4 - Creating a quote block of text
Links
TASK 5 - Remove the underline from a hyperlink
TASK 6 - Make hyperlinks block hover
TASK 7 - Creating two types of styles for links using a div class
TASK 8 - Creating two types of styles using an href class
Images and Styles
TASK 9 - Remove a border or add a border to an image
TASK 10 - Add a shadow to an image
CSS Box Model
Block and Inline elements
Block Elements
Inline Elements
HTML Div and Span
Difference between div and span
TASK 11 - Float left and float right blocks
TASK 12 - Centre a block of text with a div
TASK 13 - Centre a block of text with two divs
TASK 14 - Floating images to the right
TASK 15 - Floating images to the left
Further Tables
TASK 16 - Creating a new table
TASK 17 - Adding in some styles
TASK 18 - Formatting the display further
Summary
6 Site Examples
Create a Business Card Web Site
TASK 1 - Create a new web page
TASK 2 - Create some DIV containers
TASK 3 - Add in main image
TASK 4 - Add in header text
TASK 5 - Add in description text
TASK 6 - Add in opening hours text
TASK 7 - Add in location text
TASK 8 - Add in prices text
TASK 9 - Add in contact text
TASK 10 - Add in footer text
TASK 11 - Format text
TASK 12 - Add in body styles
TASK 13 - Add in header styles
TASK 14 - Add in styles for each block
TASK 15 - Add in footer styles
TASK 16 - Add In Canvas Styles
TASK 17 - Add in Google map
TASK 18 - Add in logo and logo styles
TASK 19 - Add in href anchor links
TASK 20 - Add in the href links styles for the header
TASK 21 - Place styles into a separate style sheet
Files for Business Card Web Site
Minify CSS
[A] - Create a separate style sheet
[B] - Minify the css
Summary
8 Graphics
Graphic formats used on the web
gif format
jpg format
png format
bmp format
tiff format
Photoshop basic principles
TASK 1 - Creating shapes in Photoshop
TASK 2 - Using text in Photoshop
TASK 3 - Saving for a web page
TASK 4 - To create a button with Photoshop
TASK 5 - Using Layers
Checking the size of images
Creating roll over images
Using Dreamweaver to create a roll over image
Create two buttons using Photoshop
TASK 6 - Creating a roll over using CSS
Exercise in Background Images
TASK 7 - Background body image
TASK 8 - Creating a background image
TASK 9 - Background position
Preparing and saving images for the web
[1] Bring an image into Photoshop
[2] Set Monitor RGB
[3] Crop the image
[4] Re-size the image
[5] Create the re-sized image
[6] Filtering the image
[7] Sharpen your image
[8] Alternative method for sharpening
[9] Save the file
[10] Add your image to a web page
Summary
9 Layouts
Page Sizes
General layouts concepts
Traditional Aspects:
Site details:
Color theory?
How to select color schemes
Web Design - Good Practice
Good Web Pages
Bad Web Pages
Responsive Design
How do we find a layout for our site?
Some Free Template Sites
Responsive Design Frameworks
A Web Site Project
Web site specification
A web site consisting of 6 pages
General considerations
Layout choice
Using Wire Frame design
Suggested Pages
[1] index.html page
[2] Products or services page
[3] FAQ or Customer Services Information
[4] Contacts page
[5] Gallery page
[6] About us page
Site map page
Site navigation
Site optimisation and submission to search engines
Things to consider
Where do I get my images from?
How many pages should the site have?
What layout should the site have?
How do I research other similar web sites?
Summary
10 Adding Functionality
Web Fonts from Adobe and Google
Google Fonts
Adobe Edge Web Fonts
TASK 1 – Add some fonts to your own web page.
Introduction to JavaScript
What is JavaScript?
What is JavaScript used for?
How do we use JavaScript?
A simple example of JavaScript
Using JQuery
What is JQuery?
Uses of JQuery
Incorporating JQuery
An illustration of JQuery
UI Accordion interface
Menu Interface
Date Picker
Adding movies to a web pages
Adding audio to a web pages
Summary
11 .htaccess Files
Things that can be done with an .htaccess file
To create an .htaccess file
Examples of .htaccess files
301 is permanent redirect
302 is temporary redirect
Defining a custom 404 error page
Stop users displaying the directory listing of a web site
Stop users displaying the details of an .htaccess file
To protect your admin area you can create an .htaccess / .htpasswd file.
Create an .htaccess file
Create the .htpasswd username / password file
Page Status Codes
Summary
12 Site Set Up
Domain Names and Web Space
Domain Name
Considerations for TLD
Web Space and Web Servers
Things to consider when looking for web hosting
After purchase of web space
Notes on Page Set Up
Page details
Site Navigation
Search Engine Optimisation (SEO)
SEO site tasks
Google Analytics
To create a new View (Profile)
Filter data by subfolder
To see Google search engine words
To display real time
To display % of use showing which links are being used
Tools for Analysing and Optimising Pages
Other facilities for testing web pages
Structured data mark-up
An introduction to Microdata
Tool for creating Microdata
Testing your Microdata
Summary
13 Forms
Basic Form Structure
Dreamweaver and Forms
Form elements
[1] Text
[2] Password
[3] Hidden
[4] Textarea
[5] Checkbox
[6] Radio Button
[7] Dropdown List
[8] Email input box (HTML 5)
[9] Submit Button
[10] Reset Button
[11] Image Button
Form Controls
Example HTML email form
Issues with email forms
Forms in HTML 5
HTML 5 and form validation
TASK 1 - The required attribute
TASK 2 - Input type of “number”
Formatting Forms in HTML 5
TASK 3 - Create a form
Summary
14 HTML 5 Design
Exercise in HTML 5 Layout
TASK 1 - Create a new HTML 5 web page
TASK 2 - Add in basic structure
TASK 3 – Add the first styles
TASK 4 - The wrapper and header styles
TASK 5 - The h1 tags
TASK 6 - Add in all text
TASK 7 - Navigation styles
TASK 8 - The section and article schematic mark-up tags
TASK 9 - The figure and hgroup styles
TASK 10 - the aside styles
TASK 11 - Add in the final group of styles to finish off the links, h tags and footer
TASK 12 - Add in htmlshv JavaScript code
Summary
This is why HTML pages can be viewed locally in your web browser from your own
computer since they do not need to be “served,” whereas dynamically generated pages
such as PHP need to be accessed through a server which handles the processing.
A basic HTML page
An HTML page adheres to defined standards which you need to meet or otherwise the
page will not display correctly. The point of having these standards is that you know the
page will look more or less the same in whatever browser you use. If you don’t follow the
rules you can’t be sure it will look the same on different browsers.
A basic web page consists of:
- declaration
- head
- body
So we start with a simple web page as follows:
<!doctype html>
<html>
<head>
<title>A web page</title>
</head>
<body>
</body>
</html>
The type Declaration tag
The <!DOCTYPE> declaration is not an HTML tag; it is an instruction to the web browser
about what version of HTML the page is written in.
It always appears at the top of the page. In this book we will be using HTML 5 and the
doc type for that is
<!doctype html>
If you look at other web pages, you will come across other type declaration such as:
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>
which is the doc type for html 4.01. As you can see, html 5 has simplified this entry.
so don’t use “odd” characters like quote marks, brackets and so on.
The file extension for a web page should be htm or html You may come across other file
extensions such as php for the PHP programming language, or .aspx for the dot net
programming language, but for all our work we will be using htm or html
Web sites can consist of a very large number of files and folders and normally we create
folders to make logical structures. A simple web site with one folder may look something
like the following:
Note that for each folder there will always be a default page and this default page will
have a file name of one of the following:
Index.html
or index.htm
or default.html
or default.htm
The default page is the “home” page for that folder or the first page that the visitor goes
to. In our example above, when the visitor enters in http://www.sitename.com the server
“knows” to send the visitor to index.html even though the visitor did not explicitly identify
that in the requested URL
Content Management Systems and HTML
Content Management Systems (CMS) are web applications that are usually database
driven and where you create web pages through a web admin interface. Some examples
of popular CMS’s are WordPress, Joomla, and so on.
To get the most out of a CMS system you do need to have an understanding of HTML and
CSS particularly if you want to do more than just place text and graphics on the pages.
Common errors that beginners make
I have taught HTML over a number of years to students of various standards but there are
a number of problems that students continuously seem to have:
- They don’t remember the basic structure of a web page and place things in the wrong
location. For example, they place the web content into the head of the page instead of the
body and so nothing displays.
- They don’t close off tags properly and don’t use the tools in their editor to see where
their mistakes are. This can result in text picking up incorrect styles or losing the page
structure.
- They are not precise enough when they enter in their styles, missing out a (:) symbol or
(“) symbol which causes the styles not to work.
Practice helps to overcome these problems. Also, using a good web editor helps as they
provide code hints and display error messages if something is not correct.
Some useful web sites
Microsoft DreamSpark
http://www.dreamspark.com/
This site allows you to download many Microsoft Products for free if you are a student or
a teacher. This is done by self-verification where you use the email address of the college
or school where you are registered. If you use your student or staff email address you can
download Microsoft Software.
HTML Reference
http://www.w3schools.com/html/default.asp
This site has become very popular and has an extensive range of reference material
covering HTML, CSS and many programming languages such as PHP.
Can I use
http://caniuse.com/
A useful web site that shows which effects can be used on which browser.
Beginners PHP
http://www.homeandlearn.co.uk/php/php.html
CoffeeCup (Commercial)
http://www.coffeecup.com/free-editor/
Free version does not have ftp and other extras
HTML editor which has many features similar to Dreamweaver.
Code anywhere
https://codeanywhere.com/
On line editor but has no visual design tools
Sublimetext
http://www.sublimetext.com/
This text editor is free with an unlimited trial version but you have to pay for the version
with ftp.
It has a color coded display which is good for coding in html and php but has no facility to
run the code in a web server in the way that Dreamweaver does, nor does it have any
layout facilities like Dreamweaver.
WebMatrix
Microsoft free code editor, good for PHP but has no real design tools. The latest version is
WebMatrix 3 - It is really intended as a programmer’s tool and is not really all that good
for page layout.
Microsoft Expression Web (Free)
http://www.microsoft.com/en-us/download/details.aspx?id=36179
This editor will not be further developed by Microsoft - up to a few months ago it was a
product you had to purchase but now is free to download.
Apanta Studio
http://www.aptana.com/
Apanta is an IDE which is used for HTML, CSS, and programming as well. It is a free to
download application and has a good support community.
Brackets
http://brackets.io/
Is an open source code editor developed by Adobe. The editor has the ability to preview
changes that you make in the web page as you make them.
Summary
This chapter gives an introduction to web pages using HTML. You can create web pages
using a text editor but there are many commercial and free editors that make page
development much easier. The chapter introduced the basic structure of a page and
illustrated tag structure which will be looked at in more detail in the next chapter.
2
HTML Tags
What’s in this chapter:
<!doctype html>
<html>
<head>
<meta charset=“utf-8”>
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
Code file: 02_HTML_Tags/files/basic_html_page_01.html
In Dreamweaver, to create a new web page, select File -> New which will list a set of
templates. These templates are just layouts that Dreamweaver have kindly created for us.
However, we just want to start with a Blank Page, so make sure that the page type of
HTML is selected and a layout of none.
You should also select a Doc Type of HTML5.
The Doc Type is simply a way to tell the browser what specification the web page will be
using so that the browser will be able to interpret the tags correctly.
Note that the web page content goes in between the body tags. One common error that is
often made is to insert the web contents in the head of the page.
Note that the above page is completely blank as it has no body content.
HTML consists of tags defined with a start and end tag. Different tags may have attributes
such as width and height for an image.
The Head and Body Elements of a web page:
<!doctype html>
<head> tag -
<body> tag -
<title> tag -
<!doctype html>
<html>
<head>
<meta charset=“utf-8”>
<title>A basic web page</title>
</head>
<body>
<h1>This is the main heading using h1</h1>
<p>This might be an introduction to the rest of the page.</p>
<h2>This is a subheading using h2</h2>
<p>More text to describe the subheading</p>
<h3>Another sub sub heading using h3</h3>
<p>Some more text describing the subheading</p>
<h1>This another main heading using h1</h1>
</body>
</html>
Code file: 02_HTML_Tags/files/html_02.html
View your page in a browser. If you are using Dreamweaver, press F12 to display the
page in the browser.
You can see this in the file article_04.html
Code file: 02_HTML_Tags/files/article_04.html
<ol>
<li>first item </li>
<li>second item </li>
<li>third item </li>
</ol>
An unordered lists
<ul>
<li>first item </li>
<li>second item </li>
<li>third item </li>
</ul>
You can change the type of bullet in the list using styles:
<ul>
<li style=“list-style-type:circle”>first item</li>
<li style=“list-style-type:circle”>second item</li>
<li style=“list-style-type:circle”>third item</li>
</ul>
You can see this in the file lists.html
Code file: 02_HTML_Tags/files/lists.html
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4
</tr>
</table>
Weblink: https://developer.chrome.com/devtools/index
In particular see https://developer.chrome.com/devtools/docs/ network which describes the
meaning of the network color bar displays.
Firefox debugger
Firebug is a Firefox extension which can be found here:
Weblink: https://addons.mozilla.org/en-US/firefox/addon/firebug/
It provides very similar facilities to those found on Google Chrome allowing you to
inspect and debug and change values.
<title>………</title>
Defines title of the web page
<p>…</p>
Paragraph tag
A line break
<br/>
<strong>….</strong>
Bold text
<i>…..</i>
Italics
<ul>
<li>Coffee</li>
Un-ordered list
<li>Tea</li>
<li>Milk</li>
</ul>
<ol>
<li>first value</li>
<li>second value</li> Ordered list
<li>third value</li>
</ol>
Summary
This chapter introduced many standard HTML tags that you will use in a web page. It
used a number of web examples to show these work. The chapter has introduced some
concepts of styles but only briefly. Styles will be further explained in the next chapter.
3
Images and Tables
What’s in this chapter:
[1] Create a new web page called table_01.html in a folder called chapter03
[2] Create a table using the following HTML code:
[2] If you are using Dreamweaver you can create a table in DESGIN view by Insert ->
Tables. This will display a dialog box which if you press OK will create a table of 3
columns by 3 rows similar to the above.
From the above we can see that <tr> is used to define ROWs and <td> is used to define
COLUMNs.
The is just a not breaking space to pad it out.
Note that setting border=”1” helps us to see the structure of the table which we may set to
border=”0” once the table has been completed.
[3] Try creating other tables with more rows or columns and change the border width to
see what happens.
[4] Try changing the width of the table to 100% so that it extends over the full width of the
page.
[5] Try merging cells together using the colspan attribute as follows:
<tr>
<td colspan=“3”> </td>
</tr>
Table Headings
Table headings <th> is the first row of a table and contain the titles of the columns. Table
headings are optional and are formatted to be bold and centred by default.
<table>
<tr>
<th>Column 1 heading</th>
<th> Column 2 heading</th>
<th> Column 3 heading</th>
</tr>
Table headings give a way of applying a different style to the first row of a table.
You can see an example of table headings and a basic table layout in the file
html_01.html
Code file: 03_Images_and_Tables/files/table_01.html
Simple Table Exercise
This exercise is to create a table that looks like the following:
1999 2014
[1] Make a table with 7 rows by 2 columns.
[2] Merge the top row together using colspan or use Dreamweaver merge table row
facility.
[3] Replace the td for the top two row by th which automatically centres and bolds the
text. If you are using Dreamweaver, the top row may already be set as th depending on
your settings.
[4] Set the width of the table to 800px as follows:
<table width=”800px”>
and set the two element widths to 400px each:
<th width=”400px”></th>
<th width=”400px”></th>
[5] Enter some text into the fields - there is some sample text provided but you can put in
any text you want.
The following is the complete html for the table:
<table width=”800px”>
<tr bgcolor=”#CCCCCC”>
<th colspan=“2”>Comparison from 1999 to 2014</th>
</tr>
<tr>
<th width=“400px”>1999</th>
<th width=“400px”>2014</th>
</tr>
<tr>
<td>Pentium III 600 MHz processor</td>
<td>Intel i5 2.4 GHz Processor</td>
</tr>
<tr>
<td>128 Mbyte Ram</td>
<td>8 Gbyte Ram</p></td>
</tr>
<tr>
<td>15 Gbyte Hard Drive</td>
<td>500 Gbyte Hard Drive</td>
</tr>
<tr>
<td>3.5 inch disc drive (1.4 Mbyte)</td>
<td></td>
</tr>
<tr>
<td>CD-Rom drive</td>
<td>DVD Read / Writer</td>
</tr>
</table>
Code file: 03_Images_and_Tables/files/table_02.html
A Gallery of Pictures
This is an exercise in creating a gallery of images using a structure of a table.
* In line styles.
* Styles in the head.
* Cascading and inheritance.
* Classes and IDs
* External style sheets.
We have mentioned before that HTML defines the structure of the web page, whereas
styles define the formatting of the web page. This is a basic concept of web pages where
there is separation between the layout and format.
Up until now we have used some styles because it is difficult to illustrate particular points
without mentioning them. Also, if you are using Dreamweaver you will find that it does
sometimes generate styles for you so you may have seen them as you work with a web
page.
A style is a “rule” that defines particular attributes. The latest definition is CSS3 which
includes a number of new features such as rounded corners, animation, fading and
transparency which can improve the appearance of your design.
Styles can be:
* in line which are applied directly to the element itself.
* in style definitions located in the head of the web page.
* in a separate style sheet referenced in the web page.
In line styles
In line styles is a way of quickly applying styles to an element without getting involved in
creating named styles. For example:
<p style=“border:thin #000 solid; padding:5px; border-radius:10px;”>This is an
example of a box around a paragraph</p>
Normally styles are given classes and are named which we will show later.
You can apply styles like this to any html element, such as h1, h2, p, img and so on.
Some examples of inline styles
Placing styles in the head of the document
The following illustrates how a style is placed into the head of a web page.
<!DOCTYPE HTML>
<html>
<head>
<meta charset=“utf-8”>
<title>Style in the head of a document</title>
<style type=“text/css”>
h1 {
color:#2E7DD0;
font-size:36px;
}
p
{
padding-left: 20px;
padding-right: 20px;
text-align: justify;
font-family: Arial;
font-size: 16px;
}
</style>
</head>
<body>
<h1>A main heading</h1>
<p>This is an example of a paragraph</p>
<p>This is another example of a paragraph</p>
<p>This is yet another example of a paragraph</p>
</body>
</html>
Code file: 04_Styles_and_Stylesheets/files/01_head01.html
With CSS, you can set many properties once, either in the head section of each HTML
document or in a remote file, and have it control every instance of that tag on your page.
Note that styles are placed between the tags <style type=“text/css”> and </style>
The example above applies styles to an h1 tag and a p tag and when you display this in
your browser you can see the result.
Style syntax
We can define style syntax in the following way:
p { color:red; text-align:center; }
p is the Selector in this example. So we are creating a ‘rule’ to target specific HTML
elements on the web page which in this example are p the elements.
In the brackets are the declarations which consist of a property and a value.
So in this example:
Property is color
Value is red
Property is text-align
Value is center
They are always structured in this form:
property:value;property:value; and so on.
so the general form of a style is
selector { property:value;property:value; }
Note how the styles are defined in the head of the document using:
<style type=”text/css”>
……..
</style>
Creating styles with Dreamweaver
Creating styles can be difficult if you have to enter them in by hand as it can be easy to
mistype a style.
Dreamweaver does have a style designer which can help you in this.
[1] On the right hand side of Dreamweaver, at the top of the tab group is a set of tabs.
Click on the CSS Designer tab.
[2] Add a CSS Source by clicking on the + symbol and select “Define in Page”.
[3] In the Selectors section click on the + symbol and enter the selector required.
[4] For example, type in h1 and then in the properties section, you can choose different
styles. (Make sure that “show set” has been ticked).
CSS - Cascading Style Sheets
Cascading Style Sheet (CSS) are statements (also known as rules) that specify how the
content of an element will appear.
Cascading in the name “Cascading Style Sheets” refer to the way in which rule takes
precedence over another.
1. Later properties override earlier properties
2. More specific selectors override less specific selectors
3. Specified properties override inherited properties
CSS can be thought of as a priority scheme which determines which style will apply
when there is more than one rule for a particular element.
Web pages can have multiple style sheets with styles applying to the same element and it
is this priority system that works out which specific stylesheet rule applies to which piece
of HTML.
The rule cascades down from the more general rule to the specific rule. The most specific
rule is chosen. So you could have an enclosing div with font type, and paragraphs within
the div with different font types and it will be the more specific paragraph rule that would
be chosen.
The following illustrates this. <p> will be at 200% not 100% because it is more specific
while the body tag is more general.
<!DOCTYPE html>
<head>
<meta content=“text/html; charset=ISO-8859-1” http-equiv=“content-type”>
<title>An example webpage</title>
<style type=“text/css”>
body {
font-size:100%;
}
p {
font-size:200%;
}
</style>
</head>
<body>
<p>This is an example of a paragraph text</p>
<br>
</body>
</html>
Code file: 04_Styles_and_Stylesheets/files/cascading_styles_example1.html
The above is illustrated in the file cascding_styles_example1.html.
So the advantage with this method is that you could have a main style sheet and then have
a separate style sheet with styles that overrides some of those styles. You can create a set
of styles that define the generic characteristics of your page and then add in more specific
styles so simplifying your style sheets.
Inheritance in Styles
Inheritance is where some style properties are inherited by their child elements.
So font-family in the body style means that all child elements inherit this property. This
means that you don’t have to include the font family in all other styles making the style
sheet much simpler.
However, not all elements are inherited such as border properties. If border properties
were inherited then every element including the p elements would have a border around
them making the page very messy.
In the following style example all text takes the font family as defined in the body style
which shows that font family styles are inherited. However, the border style is only
applied to the wrapper and not to the h1 and p elements.
<!DOCTYPE HTML>
<html>
<head>
<meta charset=“utf-8”>
<title>Inheritance in styles</title>
<style type=“text/css”>
body{
font-family:Verdana;
color:#666666;
}
.wrapper{
border: 1px solid #ff0000;
background-color:#eeeeee;
}
</style>
</head>
<body>
<div class=”wrapper”>
<h1>Main title</h1>
<p>A paragraph</p>
<p>Another paragraph</p>
</div>
</body>
</html>
Code file: 04_Styles_and_Stylesheets/files/inheritance.html
NOTE: You can force a property to inherit from its parent by placing the word inherit
after the property.
<style text=”text/css”>
––––—
</style>
We will do a couple of examples showing some basic principles.
Create a new web page called head01.html as follows. It should have a paragraph with
<p> </p> tags and use the p style in the head of the document. It should also have <h1>
tag with style.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8”>
<title>Style in the head of a document</title>
<style type=“text/css”>
h1 {
color:#2E7DD0;
font-size:36px;
}
p
{
padding-left: 20px;
padding-right: 20px;
text-align: justify;
font-family: Arial;
font-size: 16px;
}
</style>
</head>
<body>
<h1>A main heading</h1>
<p>This is an example of a paragraph</p>
<p>This is another example of a paragraph</p>
<p>This is yet another example of a paragraph</p>
</body>
</html>
Code file: 04_Styles_and_Stylesheets/files/01_head01.html
Note that all paragraphs now have the same style.
Modify this further to add in a body style:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8”>
<title>Style in the head of a document</title>
<style type=“text/css”>
body {
font-family: Arial;
font-size: 16px;
}
h1 {
color:#2E7DD0;
font-size:36px;
}
p
{
padding-left: 20px;
padding-right: 20px;
text-align: justify;
}
</style>
</head>
<body>
<h1>A main heading</h1>
<p>This is an example of a paragraph</p>
<p>This is another example of a paragraph</p>
<p>This is yet another example of a paragraph</p>
</body>
</html>
Code file: 04_Styles_and_Stylesheets/files/01_head02.html
Note that the font family and the font size have been placed into the body style. The body
style then becomes where you place the default styles for the page.
<!doctype html>
<html>
<head>
<meta charset=“utf-8”>
<title>Example of a class style</title>
</head>
<style type=“text/css”>
body {
font-family:Arial, Verdana;
font-size:16px;
}
.highlight {
color:#D02210;
font-weight:bold;
border:thin solid #000000;
padding:10px;
}
</style>
<body>
<p>Some paragraph text</p>
<p class=“highlight”>Another paragraph text</p>
<p>Yet another paragraph text</p>
</body>
</html>
Code file: 04_Styles_and_Stylesheets/files/class_01.html
TASK 3 - Creating a style for p only
The above example shows how to create a class that can be applied to any element.
However, we may want a style that can only be used for a particular selector such as p.
Suppose you want to have a special style with a smaller font and less padding. This is
shown in the example class_02.html
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8”>
<title>Example of a class style for p</title>
<style type=“text/css”>
<!—
p {
padding-left: 20px;
padding-right: 20px;
text-align: left;
font-family: Arial;
font-size: 16px;
}
p.smallerpara {
padding-left: 3px;
padding-right: 3px;
text-align: left;
font-size: 12px;
}
—>
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is an example of a paragraph</p>
<p class=“smallerpara”>This is an example of a paragraph</p>
<p>This is an example of a paragraph</p>
</body>
Code file: 04_Styles_and_Stylesheets/files/class_02.html
Here we have defined a style of p.smallerpara
Note that styles that are defined in the p element are inherited to those in the p.smallerpara
element. So p.smallerpara has the same font family even though p.smallerpara does not
define it.
Also note that the smallerpara class can only be applied to p elements.
CSS id and Class
So far we have set styles for HTML elements.
We can also create our own Selectors which can be id or class.
We have seen how to define a class selector and they can be used as many times as you
like on the page.
The id selector is used once for a unique element and is defined using the # character. An
id name is used only once on a web page whereas a class selector is used to set the style
for many items on a web page. Id selectors provide for inheritance while class selectors
do not have inheritance.
The following page gives an explanation of the differences:
#wrapper{
padding-left:20px;padding-right:20px;
}
the class selector is used for many elements and is defined using the . character (a full
stop)
.bluepara{
color:blue;
}
<!doctype html>
<html>
<head>
<meta charset=“utf-8”>
<title>Untitled Document</title>
<style type=“text/css”>
#wrapper{
padding-left:20px;padding-right:20px;
}
#wrapper p{
color:green;
}
</style>
</head>
<body>
<div id=“wrapper”>This is an example of id <p>A paragraph</p></div>
</body>
</html>
Font sizes can be Points (pt), Picas (pc), Pixels(px), Ems(em) or Percent(%)
Points (pt) and Picas (pc): Points and Picas are traditionally used in print media
(anything that is to be printed on paper, etc.). One point is equal to 1/72 of an inch. Points
and Picas are much like pixels, in that they are fixed-size units and cannot scale in size.
Pica is another print size and is 1/6 of an inch. Avoid using these sizes because monitors
are not always able to accurately set these correctly. Examples are:
p { font-size:10pt; }
p { font-size:10pc; }
Pixels (px): Pixels are fixed-size units that are used in screen media (i.e. to be read on
the computer screen). One pixel is equal to one dot on the computer screen (the smallest
division of your screen’s resolution). Many web designers use pixel units in web
documents in order to produce a pixel-perfect representation of their site as it is rendered
in the browser. One problem with the pixel unit is that it does not scale upward for
visually-impaired readers or downward to fit mobile devices. An example is:
p { font-size:10px; }
“Ems” (em): The “em” is a scalable unit that is used in web document media. An em is
equal to the current font-size, for instance, if the font-size of the document is 12pt, 1em is
equal to 12pt. In fact 1em is the hight of the letter “M”. Ems are scalable in nature, so
2em would equal 24pt, .5em would equal 6pt, etc. Ems are becoming increasingly popular
in web documents due to scalability and their mobile-device-friendly nature. The default
font setting with be 1em for a font size. “Rems” (rem) is a variation of ems. The size is
relative to the root HTML definition. Its effect is to reset the size and can be useful in
some situations when you don’t want children elements to inherit the size. Some
examples are:
p { font-size:1em; }
p { font-size:0.9em; }
Percent (%): The percent unit is much like the “em” unit, save for a few fundamental
differences. First and foremost, the current font-size is equal to 100% (e.g. 12pt = 100%).
While using the percent unit, your text remains fully scalable for mobile devices and for
accessibility. An example is:
p { font-size: 90%; }
So don’t use Points and Picas or Pixels, but use either percentages or ems both of which
are scalable. Scalable fonts are becoming much more important with responsive design
where you are creating layouts for different size browsers.
DIVs and SPAN
DIVs and SPANs are the way in which CSS uses to divide up pages and apply different
styles.
A SPAN defines a section which you can then apply styles to - I don’t tend to use spans
that much but there may be situations where you want to do that.
A DIV defines a block or a container which you can then apply styles to.
Creating a separate style sheet
In these examples we can also go back to our “Giant Snail” (article.html) exercise to try
out the external style sheet.
We can place the styles into a separate style sheet so that we can use the same styles in
different web pages.
The code to do this goes in the <head> …. </head>
<link href=“styles.css” rel=“stylesheet” media=“screen” type=“text/css” />
The reference styles.css can be either relative to this location or a full URL.
The web page example.html looks like this with a reference to a style sheet.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8”>
<title>Untitled Document</title>
<link href=“styles.css” rel=“stylesheet” media=“screen” type=“text/css” />
</head>
<body>
<p>This is an example of a paragraph</p>
</body>
</html>
The style sheet styles.css looks like this
p {padding-left: 20px;
padding-right: 20px;
text-align: justify;
font-family: Arial;
font-size: 16px;}
<style type=“text/css”>
.bluepara{
color:blue;
}
.bluepara{
color:black;
}
</style>
In this example, when you print the page, the style will have a color of black.
The @media rule is extensively used in responsive design layouts.
Summary
This chapter has looked at some of the features of styles that make them so useful. It has
looked at using external style sheets which means that many different web pages can use
the same styles. It has also looked at the concept of cascading. A good understanding of
how styles cascade will mean that you will have fewer styles and they will be easier to
maintain and modify.
5
Further Styles
What’s in this chapter:
<h1>This is a heading</h1>
Style is defined as:
h1 {
background-color:#cccccc;
}
When you create a style for these, ALL h1 tags will then have those styles.
This refines an html element.
[2] Classes
Classes are user defined styles that we can apply to any tag (selector) to change the style
for one or more tag. You can choose which ones to apply the styles to. The name of the
class can be anything that you want and in this example I have used “quote” as the class
name.
.quote { font-size:16px }
Note the full stop in front of the style definition name
This can apply to any HTML element.
[3] ids
ids are tags (selectors) which we use ONCE on the page and are often used with div
(divisions) which define the layout of a page.
#wrapper { background-color:blue; }
Note the # This applies to only one HTML element.
Style Exercises
The following Tasks illustrate many style features that you will want to control in your
web page.
For these tasks, you may want to create a new web page for each task, or you may want to
use just the one web page, adding on each style as you go – it doesn’t matter which
method you choose.
You should start by creating a web page and in the head of the web page, enter in the
styles.
STYLES
body{
font-size:16px;
background-color:#CCCCCC;
font-family:Arial, Helvetica, sans-serif;
}
BODY TEXT
.box {
background-color:#FFFF99;
font-family:Geneva, Arial, Helvetica, sans-serif;
border-style:solid;
border-width:1px;
}
BODY TEXT
Try changing the border style and other attributes of the box class.
STYLES
.myPara {
font-size:120%;
margin-left:20px;
text-indent: 20px;
}
BODY TEXT
<p class=“myPara”>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque ullamcorper, metus id
tempor dictum, magna mi ultrices ligula,
sagittis porttitor metus sapien sit amet sapien. Cras eu enim in ante sagittis ornare quis non augue. Mauris pellentesque
quam vitae
pulvinar ullamcorper. Donec tempus eleifend tortor, eu accumsan odio lobortis et. Donec sed hendrerit ipsum. Sed sed
ex ut lectus consectetur
condimentum eget aliquet neque. Mauris nisl tortor, pretium et fermentum eu, bibendum at odio. Praesent ligula arcu,
</p>
.quote {
font-size:90%;
font-style:italic;
font-family:Arial, Helvetica, sans-serif;
margin: 30px 0px 30px 0px;
padding: 20px 20px 20px 20px;
border:thin #000000 solid;
background-color:#FFFFCC;
}
BODY TEXT
<p class=“quote”>Ut eleifend, lorem sit amet viverra sollicitudin, ex massa venenatis nisl, quis faucibus velit ipsum at
odio. Cras luctus neque orci,
ut molestie libero tincidunt eu. Aliquam vel lorem non turpis facilisis laoreet. Vivamus ante mauris, condimentum non
porttitor non,
lobortis nec est. Vivamus ac risus id odio venenatis tempus. Ut malesuada tortor nec facilisis condimentum.</p>
Try changing the attributes of the quote class, margin, padding etc. to see the changes.
NOTE: We can easily look up the attributes of margin by going to Google and doing a
search with something like the following: ‘html margin’. This will return with a set of
URLs which you can go to and describe this particular attribute.
Links
Links or Hyperlinks is the way in which you move from one web page to another. We can
apply styles to give different type of effects as someone moves their mouse over the link.
link, visited, active and hover are called Pseudo Classes which add an effect to some
selectors. In this case they modify the link display.
Note that the order should be a:link, a:visited, a:hover for it to work
STYLES
a:link {text-decoration:none;}
a:hover {text-decoration:none;}
BODY TEXT
Note: :active MUST come after :hover (if present) in the CSS definition in order to
be effective.
BODY TEXT
As an additional exercise, add in the text-decoration:none to the a:link and a:hover
examples above.
TASK 7 - Creating two types of styles for links using a div class
Create a new web page and add in the following styles to illustrate how to have two
different hyperlink styles.
Code file: 05_Further_Styles/files/styles08.html
STYLES
a:link { color: #036; }
a:visited { color: #066; }
a:hover, a:active { color: #fff; background-color: #036; }
.section a:link { color: #036; }
.section a:visited { color: #066; }
.section a:hover, a:active { color: #fff; background-color:#CCCCCC }
BODY TEXT
BODY TEXT
<br/>
<a href=“http://www.wiltshire.ac.uk”>Test link</a>
<br/>
<a href=“http://www.wiltshire.ac.uk” class=“topbar”>Test link</a>
Images and Styles
TASK 9 - Remove a border or add a border to an image
Create a web page with a new class and with:
[1] a border style.
Code file: 05_Further_Styles/files/styles10.html
STYLES
.imgborder {
border:10px;
border-color:#CCCCCC;
border-style:solid;
}
BODY TEXT
BODY TEXT
CSS Box Model
One of the most important things to understand about CSS is the Box Model. Every
element that we use in the page is considered to be a rectangular box.
The properties for this box are as follow:
content, padding, border and margin.
You can understand how this element interacts from the following image:
As you can see the padding is applied around the content area. So we can use the padding
to create a gutter around the content. Then we have the border, shown in blue in the
diagram, which if applied creates a line around the padding element. We can define the
thickness in pixels of the line, the style of the line such as solid, dashed, dotted.
After the border there is the margin. This is transparent and we can use it to create and
control spacing between different boxes. Padding, borders and margins are optional and
they are set to zero as default setting. If we want to them set back to zero we can use the
universal selector and the following code:
*{ margin:0; padding:0; }
If we assign a width and height to a box, it refers to the content of the box only. The
padding, borders, and margins are then added to this value and summing all together gives
the total box width. So if I want a total box to be 100px wide, one way is to use the
following values:
*{ margin: 10px; padding: 10px; width: 60px; }
This consists of a total margin of 20px and a total padding of 20px plus the width of the
content.
So in summary, the padding adds in space between the content and the border, and
the margin adds in space between the border and other content.
There are two web page examples of this:
Code File: 05_Further_Styles/files/CSS_Box_Model_Margin.html
This shows a box with a margin
Code file: 05_Further_Styles/files/CSS_Box_Model_Padding.html
This shows a box with padding
Block and Inline elements
Block Elements
Some elements will always appear to start in a new line in the browser. These are called
block level elements and example of these are <h1>, <h2>, <p> , <div>
Inline Elements
Some elements always appear to continue on the same line as neighbouring elements.
These are known as inline elements. Examples of these would be <i>, <strong> and
<span>.
It is quite easy to demonstrate the difference between block and inline elements using a
simple web page and adding borders to the styles.
If we look at the web page:
Code file: 05_Further_Styles/files/block_and_inline.html
we will see that it is made up of a mixture of block level and inline elements. We can
show this more clearly by applying border styles.
Code file: 05_Further_Styles/files/block_and_inline.html
All block level elements have been identified by a border of orange, and all in line
elements have been identified with a border of green.
HTML Div and Span
In the following tasks we will be using the example text in the file
div_and_span_example_text.txt
<span style=”background-color:#00ff00;”>
Some text here
</span>
Place the example span around some text in one of the paragraphs and view in a browser.
View the page in the browser.
Code file: 05_Further_Styles/files/div01.html
<div style=“float:left;width:300px;height:auto;”>
First block of text here
</div>
<div style=“float:right;width:300px;height:auto;”>
Second block of text here
</div>
Code file: 05_Further_Styles/files/div03.html
<div style=“width:60%;margin-left:auto;margin-right:auto;height:auto;”>
<div style=“float:left;width:40%;height:auto;”>
First block of text here
</div>
<div style=“float:right;width:40%;height:auto;”>
Second block of text here
</div>
</div>
Code file: 05_Further_Styles/files/div04.html
<div style=“float:left;width:550px;”>
<div style=“width:300px;float:right;”><img src=“snail.jpg” width=“300px” /></div>
Enter the text here
</div>
Code file: 05_Further_Styles/files/div05.html
<div style=“float:left;width:550px;”>
<div style=“width:300px;float:left;”><img src=“snail.jpg” width=“300px” /></div>
Enter the text here
</div>
Code file: 05_Further_Styles/files/div06.html
Further Tables
In a previous chapter we looked at tables. Tables are used for tabular data of course.
Tables can also be used to layout areas of a web page but you should try to restrict the use
of tables for tabular data because it is often cleaner and easier to use DIVs. If we go back
a number of years, tables were used to define web page layout, nowadays using tables for
page structure is frowned upon.
HTML 5 and CSS 3 enable the creation of really nice looking tables which we will look at
here.
body {
font-family:Arial, Helvetica, sans-serif;
}
table {
width:550px;
border-collapse:collapse;
}
th, td
{
padding: 5px 10px 5px 10px;
}
tr:nth-of-type(odd) {
background-color:#efefef;
}
tr:hover {
background: #cccccc;
}
Code file: 05_Further_Styles/files/table_02.html
th
{
background: #cccccc;
text-align: left;
}
Add in the following class to format the column used for displaying the salary:
.money {
text-align:right;
}
Then add class=”money” to the <th> and <td> for the salary column.
Code file: 05_Further_Styles/files/table_03.html
Summary
This chapter looks at how to use styles in more detail. It looks at placing styles into
external style sheets and gives various examples of the some of the techniques that you
may want to use. It also looked at the box model and the difference between block level
and in line elements.
6
Site Examples
What’s in this chapter:
<body>
<div id = “container”>
<div id=“header”>
</div>
<div id=“logo”>
</div>
<div id=“image”>
</div>
<div id =“description”>
</div>
<div id=“openinghrs”>
</div>
<div id=“location”>
</div>
<div id=“prices”>
</div>
<div id=“contactus”>
</div>
<div id=“map-canvas”>
</div>
<div id=“footer”>
</div>
</div>
</body>
Code file: 06_Site_Examples\files\BusinessCardLayout\index_task02.html
This will constrain the image to the size of the web page.
Code file: 06_Site_Examples\files\BusinessCardLayout\index_task03.html
<style type=“text/css”>
#header {
Background-color:#000000;
}
</style>
Code file: 06_Site_Examples\files\BusinessCardLayout\index_task04.html
07824728621
Code file: 06_Site_Examples\files\BusinessCardLayout\index_task09.html
#header {
background-color: #000000;
color: #FFF;
margin:0px;
padding: 20px;
font-size: 120%;
}
Code file: 06_Site_Examples\files\BusinessCardLayout\index_task13.html
TASK 14 - Add in styles for each block
For the description div:
#description {
padding-top: 20px;
padding-right: 250px;
padding-bottom: 10px;
padding-left: 250px;
text-align: center;
}
#description h1 {
font-size:120%;
color:#F30;
}
and then for each of the other divs openinghrs, location and prices use the same styles.
Note that we could do multiple styles like this:
#prices h1, #location h1 {
}
Code file: 06_Site_Examples\files\BusinessCardLayout\index_task14.html
For the example web page that we have just created for Archibald’s Barbers, extract the
styles and place them into a separate style sheet called styles.css.
This style sheet should be placed in a new folder called stylesheets
Now in your web page create a link to the styles.css which will look something like:
Display the web page in your browser to make sure the styles are working as expected.
<ul>
<li>One large tomato</li>
<li>A pinch of salt</li>
<li>3 kg of potatoes</li>
</ul>
The list-style-type CSS property can have values to give different appearance to the
bulleted listing:
So
list-style-type:square
displays a square bullet list:
<ul style=”list-style-type:square”>
<li>One large tomato</li>
<li>A pinch of salt</li>
<li>3 kg of potatoes</li>
</ul>
Code file: 07_Lists_and_Menus/files/lists.html
Here is a list of some of the more common list-style-type.
decimal 1, 2, 3, 4, etc.
lower-latin a, b, c, d, etc.
upper-latin A, B, C, D, etc.
none No marker.
Ordered Lists
Ordered lists are defined by <ol> with each element using <li>
<ol>
<li>One large tomato</li>
<li>A pinch of salt</li>
<li>3 kg of potatoes</li>
</ol>
To add style to the order list we can add the type attribute:
Type
type=“1” The list items will be numbered with numbers (default)
type=“A” The list items will be numbered with uppercase letters
type=“a” The list items will be numbered with lowercase letters
type=“I” The list items will be numbered with uppercase roman numbers
type=“i” The list items will be numbered with lowercase roman numbers
<ol type=”A”>
<li>One large tomato</li>
<li>A pinch of salt</li>
<li>3 kg of potatoes</li>
</ol>
Code file: 07_Lists_and_Menus/files/lists.html
Using images in lists
Another CSS style that can be used with lists is the list-style-image which allows us to place an image of our choice
against the list item.
To illustrate this, create a new HTML web page called listimages.html
An image can be added by using the style:
<style type=“text/css”>
ul
{
list-style-image:url(lightbulb.png);
}
</style>
Property
Create a menu using an Unordered List
This is an example of a menu using CSS and an unordered list.
Unordered lists are usually lists with icons but in a menu we use the style list-style-type:
none; to disable any icon.
We can use the features of an unordered list with different colors in the various link states
to give our effects.
Create a new web page called index_menu.html and copy the following unordered list
into the body.
<div class=“menu”>
<ul>
<li><a href=“index.html”>Home</a></li>
<li><a href=“about.html”>About</a></li>
<li><a href=“location.html”>Location</a></li>
<li><a href=“contact.html”>Contact Us</a></li>
<li><a href=“shop.html”>Shop</a></li>
</ul>
</div>
Now view this in the web page.
Now we add the styles to format the menu as follows:
<style type=“text/css”>
.menu ul {
margin: 0;
padding: 0;
width:185px;
list-style-type: none;
}
.menu ul li a {
text-decoration: none;
color: white;
padding: 10.5px 11px;
background-color: #005555;
display:block;
}
.menu ul li a:visited {
color: white;
}
.menu ul li a:hover, .menu ul li .current {
color: white;
background-color: #5FD367;
}
</style>
Code file: 07_Lists_and_Menus/files/index_menu.html
Example of a menu in a web page
To demonstrate this in a web page there is an example layout in 06-Navigation in the
layout folder which we can use.
In 07_Lists_and_Menus in the layout folder:
[1] Download the index.html page and view it in a browser. This page is a basic layout
with blank images and no styles applied.
Code file: 07_Lists_and_Menus/files/layout/index.html
[2] Download the images in the images folder and place them all in a folder called
images.
[3] Download the styles.css page.
[4] Now add the link to the styles.css page to the index.html page.
View this page in the browser and you should see that it has been formatted by the styles.
You should see that the navigation is not styled as we have not added in the styles for that
yet.
Code file: 07_Lists_and_Menus/files/layout/index2.html
[5] Use the styles from the previous exercise and put them in the menu.css stylesheet then
add this stylesheet to the index.html page.
Code file: 07_Lists_and_Menus/files/layout/index3.html
[6] View the page in the browser.
[7] Now we can copy the index.html to create files called about.html, contact.html,
location.html and shop.html and when we click on the navigation, the pages should work
correctly.
Note the use of class=”current” to define which menu item is highlighted.
This is shown in the folder 07_Lists_and_Menus within the layout_multi folder.
CSS Mouseover Buttons
This method gives a simple horizontal menu with submenus. It uses lists and CSS to configure the lists.
The html for the menu is as follows:
<ul id=“menu”>
<li><a href=”#”>Home</a></li>
<li><a href=”#”>About Us</a>
<ul>
<li><a href=”#”>The Team</a></li>
<li><a href=”#”>History</a></li>
<li><a href=”#”>Vision</a></li>
</ul>
</li>
<li><a href=”#”>Products</a>
<ul>
<li><a href=”#”>Cozy Couch</a></li>
<li><a href=”#”>Great Table</a></li>
<li><a href=”#”>Small Chair</a></li>
<li><a href=”#”>Shiny Shelf</a></li>
<li><a href=”#”>Invisible Nothing</a></li>
</ul>
</li>
<li><a href=”#”>Contact</a>
<ul>
<li><a href=”#”>Online</a></li>
<li><a href=”#”>Right Here</a></li>
<li><a href=”#”>Somewhere Else</a></li>
</ul>
</li>
</ul>
The CSS for this is
ul {
font-family: Arial, Verdana;
font-size: 14px; margin: 0;
padding: 0;
list-style: none;
}
ul li {
display: block;
position: relative;
float: left;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #2C5463;
margin-left: 1px;
white-space: nowrap;
}
ul li a:hover {
background: #617F8A;
}
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 11px;
}
li:hover a {
background: #617F8A;
}
li:hover li a:hover {
background: #95A9B1;
}
Code file: 07_Lists_and_Menus/files/cssmenu.html
The advantage with this method is that it requires no clever programming.
Exercise
[1] Create a new web page and in the body of the web page copy the above list. Save the
web page as cssmenu.html in the folder 07_Lists_and_Menus.
[2] In the head of the web page, create a style section and add the above css code into it.
[3] When you display the web page in your browser you should see a horizontal menu
representing the buttons which is created using html lists.
Summary
This chapter illustrates various methods that can be used to create dropdown menu lists.
Using lists and css to create menus is very flexible and is the method that you will come
across over and over again. Modifying and adding new menu items is very straight
forward as it is just a case of editing the text.
8
Graphics
What’s in this chapter:
gif format
Pros of GIF:
• Can support transparency
• Can do small animation effects
• ‘Lossless’ quality–they contain the same amount of quality as the original, except
of course it now only has 256 colors
• Great for images with limited colors, or with flat regions of color
Cons of GIF:
• Only supports 256 colors
• It’s the oldest format in the web, having existed since 1989. It hasn’t been
updated since, and sometimes, the file size is larger than PNG.
jpg format
Pros of JPEG:
• 24-bit color, with up to 16 million colors
• Rich colors, great for photographs that needs fine attention to color detail
• Most used and most widely accepted image format
• Compatible in most OS (Mac, PC, Linux)
Cons of JPEG:
• They tend to discard a lot of data
• After compression, JPEG tends to create artefacts
• Cannot be animated
• Does not support transparency
png format
Pros of PNG
• Lossless, so it does not lose quality and detail after image compression
• In a lot ways better then GIF. To start, PNG often creates smaller file sizes than
GIF
• Supports transparency better than GIF
Cons of PNG:
• Not good for large images because they tend to generate a very large file,
sometimes creating larger files than JPEG.
• Unlike GIF however, it cannot be animated.
• Not all web browsers can support PNG.
bmp format
Pros of BMP:
• Works well with most Windows programs and OS, you can use it as Windows
wallpaper
Cons of BMP:
• Does not scale or compress well
• Again, very huge image files making it not web friendly
• No real advantage over other image formats
tiff format
Pros of TIFF:
• Very flexible format, it supports several types of compression like JPEG, LZW,
ZIP or no compression at all.
• High quality image format, all color and data information are stored
• TIFF format can now be saved with layers
Cons of TIFF:
• Very large file size–long transfer time, huge disk space consumption, and slow
loading time.
Photoshop basic principles
The Photoshop display consists of:
· Left hand side is the tool bar.
· Right hand side is the layers.
Two important tool bar elements are the Pointer icon, and the Move icon.
Pointer icon:
Move icon:
When you create a new object, that object will be selected. To deselect it, you click on the
Pointer icon.
To select something in the toolbar, click on the toolbar object, right click on your mouse
and it will display other options.
Photoshop uses layers where each layer is a separate drawing area. So you can create one
layer with one shape and then create another layer with another shape and place one on
top of another. Layers can be hidden, or merged with other layers.
To display the layer panel select Wndows -> Layers
To create an effect, double click on the layer which will display a set of layer styles.
Tick a box to use that style and clicking on the style name will then display a set of
options for that particular style.
Remember that standard screen sizes are now around 1280px and 800px so those sizes
give an indication of the size of your images on the web.
Tick the box means that the JavaScript that is created will
Preload rollover
include preloading of the images so that it gives no delay
image:
when the image is displayed.
When clicked, Go to
The destination URL
URL:
<style type=“text/css”>
a.rollover {
display: block;
width: 110px;
height: 35px;
text-decoration: none;
background: url(“buy_now.png”);
}
a.rollover:hover {
background-position: -110px 0;
}
</style></style>
And in the body you will need the class “rollover”
<a href=”#” class=“rollover” title=“Buy Now”></a>
<style type=“text/css”>
body {
background-image: url(“flowers.gif”);
color: black;
padding: 20px;
font-family:Baskerville, “Palatino Linotype”, Palatino, “Century Schoolbook L”, “Times New Roman”, serif;
}
</style>
[4] In the main body of the web page, copy the body text from the text file grasses.txt
from the course material for this Chapter.
[5] Format the text with <h1> tag for the main title, <h2> tag for the secondary titles and
<p> for each of the paragraphs.
[6] View the resulting web page in your browser or upload to the web server and test it on
your web server.
Code file: 08_Graphics/files/background01.html
<style type=“text/css”>
body {
background-image: url(“vert.png”);
background-repeat: repeat-x;
background-color:#3399cc;
color: black;
padding: 20px;}
</style>
[5] In this example, I have set the page background to the same solid color as the gradient
color. Then I have set the repeat direction to the horizontal direction only. Display the
result in the browser.
<style type=“text/css”>
body {
background-image: url(“html5_logo.jpg”);
background-repeat: no-repeat;
background-position: center top;
color: #665544;
padding: 20px;}
</style>
[4] Display the results in your browser.
The position of the background in this case is defined by background-position, when the
image is not being repeated.
Experiment with background-position to set the position as appropriate. Note also, that
you can set the position as % so:
background-position: center top;
is the same as:
background-position: 50% 50%;
Preparing and saving images for the web
Using images on a web page is essentially an optimising process. Different displays have
many factors which change the appearance of the image: contrast, depth of colors, viewing
angle and so on. We can apply filters and make adjustments to an image so that it looks
reasonable the same on different devices.
These exercises use Photoshop but you can do them just as well in other editors such as
http://pixlr.com which seems to work best in Firefox.
[a] Click on Moon symbol on layers and select curves - it creates a layer and you can
adjust the contrast. Normally you adjust it to look like an S-curve.
[b] Click on Photo Filter… and add a warming filter or other filter to the image.
[c] Click on levels, which allow you to make some adjustments to the levels.
[d] Click on Brightness/Contrast which allows you to make some adjustments to the
brightness and contrast.
* Layout concepts.
* Good and bad design practices.
* A web site project.
Web site design requires a certain mind set to understand what a visitor will find attractive
and hence will keep them on your site. This includes concepts such as color harmony,
attractive positioning of images and content, good navigation and site organisation. This
chapter looks at these ideas.
Page Sizes
· Pages are usually aimed at 960 to 1000 pixels when designing for desk top computers.
· Recent trends are to responsive web design which use layouts that adjust to browser
size and device and where elements are modified to optimise for the particular device.
· A fixed width layout - elements can be accurately controlled but can get large gaps
particularly around the edges of the web page and it will not work well on devices that
are not able to display the defined width.
· A liquid layout - pages fill the size as the browser changes size and is good for
desktop displays but only really works if used with responsive techniques.
Traditional Aspects:
There are many concepts to layout but we can consider the following:
· A grid layout system – positioning items on a web page can be difficult if you
have no inbuilt structure on your page. However, there are a number of grid
system style sheets that you can download from the internet such http://960.gs/.
These grid systems make placement of text and images much easier. Responsive
design frameworks have a grid system built in.
· A standard color scheme – the idea with defining a color scheme is to give
harmony throughout the design. The colors that you select can give a certain
impression such as warm or cool. There are a number of web sites which have
interactive applications where you start with a base color and the application then
shows a set of complimentary colors.
Choose the color scheme and then choose cold or warm and then click export.
· A hierarchy of information - your pages need to be logical in the way that they
are grouped using menu and sub menus. The user needs to easily be able to see
where they are in the hierarchy of the web site. This can be achieved using a
menu system which highlights the current location. It may also have a
“breadcrumb” system. This becomes more important the larger the web site.
Site details:
Color theory?
We can think of color theory as:
Complementary - the way we see colors in relationship with others.
Contrast - the way we see how one color compares with another.
Vibrancy - defines the brightness or loudness of the colors.
http://www.free-css.com/
This has free layouts but some are a little old so you may have to make sure that they
work with modern browsers.
As an exercise, go to the free template list and find “simple company” template which is a
responsive design layout based on Twitter Bootstrap. Download it, then extract the zip
file and look at the index.html file.
Note that you can do a search for “simple company” with a Responsive layout.
http://www.templateworld.com/index.html
This site has a good range of templates which you can download.
http://www.freehtml5templates.co.uk/
This site is all HTML 5 templates – These may have a link back to their site but you can
remove it.
HTML 5 Up is another framework type system which is also a responsive css template.
http://html5up.net/
flypixel - Awesum design freebies by kickass designers from all over the world
http://flypixel.com/
A Web Site Project
This section looks at how you might tackle working to a specification and designing a web
site to meet particular needs.
The outcomes are:
[1] Create layout, structure and styles for a website consisting of a number of pages
depending on the requirements.
[2] Use website software tools to prepare content for a website.
[3] Publish a website.
Web site specification
Choose a subject for a web site, e.g. a site about:
Layout choice
You need to decide a layout using DIVs which will fit into your requirements. In this
project, a 750 pixel wide area has been suggested but, you may modify this as you see fit.
Or you may want to look at downloading a free template from the many web sites that
provide these.
Using Wire Frame design
A wire frame is a way of laying out web pages using a kind of flow diagram. It is an
approach that allows you to see how pages are linked together and to test the navigation.
There are a number of online tools available such as Lumzy
http://www.lumzy.com/app/
This allows you to create simple layouts and prototype the web pages. The more
advanced programs allow you to have multiple developers and have a certain amount of
interaction so that you can demonstrate your concepts to a customer before spending time
on the final version.
Suggested Pages
[1] index.html page
This is the home page or initial page of the web site and will describe the purpose of the
site. This will be either index.html, index.htm, default.html, default.htm.
Site navigation
There should be consistent navigation around the site. The navigation should be clear as
to which page you are on and should match your color scheme.
Google Fonts
Google fonts can be found at http://www.google.com/fonts/
Using the fonts is very easy:
· Choose a particular font that you want
· Click on the “Quick use” button
· Copy the give stylesheet and add into <head> of your web page.
· Copy the font family definition name and add to the style.
For example:
The font Carrois Gothic SC gives a style sheet as:
<link href=‘http://fonts.googleapis.com/css?family=Carrois+Gothic+SC’ rel=‘stylesheet’
type=‘text/css’>
Integrate your fonts into the styles with something like:
h1 {
font-family: ‘Carrois Gothic SC’, sans-serif;
font-size: 36px;
}
Code file: 10_Adding_Functionality/files/google_font_example.html
Note that it may not work in all browsers but it will drop back to a default appearance if
the browser is not able to support it.
You should be aware that any font will increase the time to load the page, so you would
not add too many different fonts onto the same web page.
Google documentation
https://developers.google.com/fonts/docs/getting_started
This page provides you with a description of Google fonts and how to use them.
In particular, note the beta features:
https://developers.google.com/fonts/docs/getting_started#Effects
These are font effects that are available, but they do not work on all browsers. Each font
has a list of compatible browsers.
<style type=“text/css”>
h1 {
font-family: font-family: asset, serif;
font-size: 36px;
}
</style>
Code file: 10_Adding_Functionality/files/adobe_edge_font_example.html
As with Google fonts there will be a payload added to the web page, so you would not add
too many different fonts.
What is JavaScript?
JavaScript is a programming language which runs on your PC, table or smart phone. The
program script is downloaded with a web page onto your computer. You create
JavaScript on the web page and you can have separate JavaScript files.
When you put JavaScript into the head of a web page, you always have to identify it as a
script in this way.
[4] In the <body>…</body> tags you can enter any text that you want.
[5] Run your web page in the browser and you should get an alert message on your page.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8”>
<title>A JavaScript Page</title>
<script language=“javascript” type=“text/javascript”>
alert(“A JavaScript Pop-up”);
</script>
</head>
<body>
<h1>An example of Javscript</h1>
</body>
</html>
Code file: 10_Adding_Functionality/files/javascript.html
Using JQuery
What is JQuery?
JQuery is based on JavaScript which is a client side programming language that runs in
the web browser. In the past, this has caused problems as different browsers implement
browser standards differently and hence you had to write and test code for different
browsers.
JQuery is a JavaScript framework which uses a set of pre-defined functions compatible
with modern browsers. When you use JQuery you can be confident that it will work on
the majority of browsers that are being used today, and as new versions of browsers are
released the base framework will be updated to ensure it works with those as well.
This section gives a brief introduction to JQuery
Uses of JQuery
* Creating forms to do calculations on the client PC
* Validating data before data is submitted to a database
* Creating displays that give a better user experience, for example, displaying error
messages in data validation
* Using the user interface plug in such as accordion, date picker, progress bar and so on as
shown in http://jQueryui.com/ and other web sites such as http://jquery-plugins.net/
* Using the many plug ins that have been developed by other developers
* Developing AJAX applications
Incorporating JQuery
There are two ways to incorporate JQuery script into a web page, the first method is to
download the JavaScript file from the JQuery web site and include in as a linked file, and
the second method is to use a hosted JavaScript file which is linked onto your web page.
So for example to include jquery from an external hosted system, use:
<script src=“http://code.jquery.com/jquery-1.8.3.js”></script>
An illustration of JQuery
In this tutorial we will not go into the details of JQuery, however it is possible to create
working examples very easily from the JQuery user interface web site.
The site
http://jqueryui.com/
includes a number of common User Interfaces which you can incorporate into your own
web site with minimum effort and very little programming. In fact you don’t actually
need to understand JQuery to be able to use these interfaces.
You should by now know enough about the structure of a web page, and be able to read
example web pages and then place that code into your own web pages. These JQuery
examples require you to do that.
UI Accordion interface
As an example, we will use the Accordion interface which is illustrated below. Just copy
and save as an html page called accordion.html. This example comes from
http://jqueryui.com/accordion/ which lists all the various options available.
Click headers to expand/collapse content that is broken into logical sections, much like
tabs. Optionally, toggle sections open/closed on mouseover.
The underlying HTML mark-up is a series of headers (H3 tags) and content divs so the
content is usable without JavaScript.
<!doctype html>
<html lang=“en”>
<head>
<meta charset=“utf-8” />
<title>JQuery UI Accordion - Default functionality</title>
<link rel=“stylesheet” href=“http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css” />
<script src=“http://code.jquery.com/jquery-1.8.3.js”></script>
<script src=“http://code.jquery.com/ui/1.9.2/jquery-ui.js”></script>
<script>
$(function() {
$( “#accordion” ).accordion();
});
</script>
</head>
<body>
<div id=“accordion”>
<h3>Section 1</h3>
<div>
<p>
Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer ut neque. Vivamus nisi metus, molestie vel,
gravida in, condimentum sit amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut odio.
Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.</p>
</div>
<h3>Section 2</h3>
<div>
<p>
Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet purus. Vivamus hendrerit, dolor at aliquet
laoreet, mauris turpis porttitor velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In suscipit faucibus
urna.</p>
</div>
<h3>Section 3</h3>
<div>
<p>
Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis.
Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero
ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis lacinia ornare, quam ante aliquam nisi, eu
iaculis leo purus venenatis dui.</p>
<ul>
<li>List item one</li>
<li>List item two</li>
<li>List item three</li>
</ul>
</div>
<h3>Section 4</h3>
<div>
<p>Cras dictum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacin mauris vel est.
</p>
<p>
Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus.
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</p>
</div>
</div>
</body>
</html>
Menu Interface
jqueryui includes a menu system as described at http://api.jqueryui.com/menu/
Copy the following text into an html page called menu.html
<!doctype html>
<html lang=“en”>
<head>
<meta charset=“utf-8”>
<title>menu example</title>
<link rel=“stylesheet” href=“http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css”>
<style>
.ui-menu {
width: 200px;
}
</style>
<script src=“http://code.jquery.com/jquery-1.9.1.js”></script>
<script src=“http://code.jquery.com/ui/1.10.2/jquery-ui.js”></script>
</head>
<body>
<ul id=“menu”>
<li><a href=”#”>Item 1</a></li>
<li><a href=”#”>Item 2</a></li>
<li><a href=”#”>Item 3</a>
<ul>
<li><a href=”#”>Item 3-1</a></li>
<li><a href=”#”>Item 3-2</a></li>
<li><a href=”#”>Item 3-3</a></li>
<li><a href=”#”>Item 3-4</a></li>
<li><a href=”#”>Item 3-5</a></li>
</ul>
</li>
<li><a href=”#”>Item 4</a></li>
<li><a href=”#”>Item 5</a></li>
</ul>
<script>
$( “#menu” ).menu();
</script>
</body>
</html>
Date Picker
On the web site http://jqueryui.com/datepicker/ there is an example on creating a date
picker. Create a web page and create the date picker, then modify the script to add in the
dateFormat to give a UK format rather than the default US format.
You will need to look up the API documentation at http://api.jqueryui.com/datepicker/ and
look at the dateFormat method to see how to do it.
Adding movies to a web pages
In HTML 5 the process of adding movies to web pages has become very easy.
Previous versions of HTML required plugins such as flash but HTML 5 introduces the
video tag.
Use the following syntax:
<video width=“320” height=“180” controls>
<source src=“movie.mp4” type=“video/mp4”>
<source src=“movie.ogg” type=“video/ogg”>
<source src=“movie.webm” type=“video/webm”>
Your browser does not support the video tag.
</video>
The video tag has a width and height which you should always try to define, otherwise
your page may change its appearance if the video is of a different size than you expected.
The controls attribute will add in the video controls for you.
The other attribute is loop which causes the video to loop continuously.
Currently, the formats that are supported are by HTML 5 mp4, ogg and webm.
Note that not all browsers support all formats so normally you would provide multiple
versions of the video in the different formats.
The full html 5 page is:
<!DOCTYPE HTML>
<html>
<head>
<title>Movie example</title>
</head>
<body>
Code file: 10_Adding_Functionality/files/movie.html
Note for it to work in IE9 you have to put
<meta http-equiv=“X-UA-Compatible” content=“IE=Edge”/>
In the head of the web page.
Adding audio to a web pages
In HTML 5 the process of adding audio to web pages has become very easy.
Previous versions of HTML required plugins such as flash but HTML 5 introduces the
audio tag.
Use the following syntax:
<audio controls>
<source src=“mp3_03.mp3” type=“audio/mpeg”>
<source src=“mp3_03.mp3” type=“audio/ogg”>
Your browser does not support the audio element.
</audio>
The controls attribute adds in the audio controls for you.
Currently, the formats that are supported are by HTML 5 mp3, wav and ogg.
Note that not all browsers support all formats so normally you would provide multiple
versions of the audio in the different formats.
The full html 5 page is:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8”>
<meta http-equiv=“X-UA-Compatible” content=“IE=Edge”/>
<title>Audio example</title>
</head>
<body>
<audio controls>
<source src=“mp3_03.mp3” type=“audio/mpeg”>
<source src=“mp3_03.mp3” type=“audio/ogg”>
Your browser does not support the audio element.
</audio>
</body>
</html>
Code file: 10_Adding_Functionality/files/audio.html
Summary
This chapter introduced methods to add functionality to your web page by looking at
external font systems and JQuery. These add an extra touch to your site which make it
look much more professional. You don’t have to be a programmer to use JQuery as
developers have created applications that can be added to your web site by cutting and
pasting.
11
.htaccess Files
What’s in this chapter:
This chapter is not actually about HTML or anything to do with HTML pages but is about
a special file that is used on Apache web servers. It is a very useful file and provides
many features such as redirecting pages from one location to another or defining a custom
404 error page. The great thing about it is that it is a text file and can be easily created.
The file is .htaccess
NOTE the full stop (.) at the front of the file name.
NOTE that .htaccess files only work on Linux type web servers, not on Windows web
servers.
One use of an .htaccess file is that it can be used for 301 redirects which tell a web
browser that the page has a different file name or folder name - it is used in situations
where you move a page and you want Google to correctly understand the move.
As an Apache server configuration file, .htaccess is very powerful but even the slightest
syntax error like a missing bracket can result in your web site not displaying correctly or
at all.
Since .htaccess is a configuration file, make sure your FTP client is configured to show
hidden files. This is usually an option in the program’s preferences/options.
When you create the .htaccess file, you will need to upload it to your web server. Often
the file is located at the root of the web server, but there may be situations where you only
want it to effect a particular folder in which case it will go into that folder.
Things that can be done with an .htaccess file
· Permanently redirect or temporarily redirect one URL to another - useful for
informing search engines about which files to redirect to
· Prevent browsers displaying a list of folders and files on your web site.
· Password protect a folder of a web site.
· Create a custom 404 error page.
To create an .htaccess file
[1] Create a new file called .htaccess on your local PC using a text editor. Note that an
.htaccess file has a dot at the first character.
[2] For a Windows PC you may not be able to create a file with .htaccess, so create a file
called .htaccess with the intention of uploading it to the server and then changing the file
name on the server.
Examples of .htaccess files
# Redirect old file path to new file path
Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html
# Redirect old file path to new file path - not normally used
Redirect 302 /oldpage.html http://www.yoursite.com/newpage.html
# Custom 404 error page
ErrorDocument 404 /errordocs/error404.htm
# Stop displaying of htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
To protect your admin area you can create an .htaccess /
.htpasswd file.
One feature that is quite handy is the ability to password protect an area of a web site.
This can be done using .htaccess / .htpasswd files. The system using “Basic
Authentication” and provides some protection to your folder.
Go to http://www.htaccesstools.com/htaccess-authentication/
In the first box enter some optional text which gets displayed in the login box
In the second box you need to enter the file path name to a second file htpasswd file. The
htpasswd file is where the list of users / passwords is to be located.
Click on the button, copy the text and place it into a text file. Name this file .htaccess and
upload it to the folder that you want to protect. In this case this would be the /admin/
folder.
An example of this is:
AuthType Basic
AuthName “Protected Area”
AuthUserFile /admin/.htpasswd
Require valid-user
Go to http://www.htaccesstools.com/htpasswd-generator/
In the first box enter the username.
In the second box enter the password.
Click the button, copy the text and place it into a text file. Name this file .htpasswd and
upload it to a suitable location on your server. This can be anywhere on your server, but
usually in a folder that is outside the web space. The location is the same location as was
entered in (1) above.
The folder as defined in (1) should now be protected by the username / password as
defined in (2)
paul:$apr1$t/B1YqZj$S6wiKCAcJu.4.eoohNpEF.
Page Status Codes
You may be wondering what 404 pages are and what are page status codes.
When you make a HTTP request to a web server for a web page, the response from the
server will be one of the pages status codes. Normally the status will be 200 which means
that the request was successful but there are many error codes.
The codes are divided up into:
1xx Informational
2xx Success
3xx Redirection
4xx Client Error
5xx Server Error
The following is a brief description of many of the page error codes although the only
ones you are likely to see are 404 (page not found) and 500 (internal server error).
Summary
This chapter gives an overview of the htaccess file that is used on Linux type web servers.
This type of file allows you to do all kinds of functions that are useful with web sites, such
as redirecting pages, defining a protected area and so on.
12
Site Set Up
What’s in this chapter:
Domain Name
Go to a domain name listing site to identify a domain name that has not been taken and is
available to register. There are a number of these sites such as www.who.is
You can use these sites to research an available domain name.
Enter in your suggested domain name e.g. Alfiethedog.com
Try other TLD (Top Level Domains) of say:
.uk
.eu
.biz
.com
.org
.net
.edu
etc.
The list of TLDs is expanding all the time.
Page details
Sitemap: http://www.wiltshire.ac.uk/sitemap.xml
User-agent: *
Disallow: /dbhelp/
Disallow: /download/
Disallow: /error/
Disallow: /include/
Disallow: /induction/
An introduction to Microdata
Microdata consists of 3 elements: itemscope, itemtype and itemprop.
Use itemscope to identify that the content item as follows:
<div itemscope>
PHP Tutorials eBook
</div>
The itemtype is used as an attribute to define the type.
http://schema.org/Book indicates that this item is a book
We can then use the itemprop to add properties such as name.
Forms are used on the web to allow users to input data and then have that data processed
in some way. For example, a form could be for collecting comments from a user.
The processing can only be done using a script which runs on the server, which might be a
PHP script that stores the data in a database, or it might send an email to someone.
We are not covering PHP in this book so we can’t really do a great deal with the data.
However, we can create an email form that sends the data by email and show the principle
of forms, and we can look at validation and layouts.
Basic Form Structure
The basic structure of a form is:
<form action=”….” method=”…”>
</form>
Action is where the data is to be sent to. Usually this is a URL of a PHP script.
Method is the either post or get which defines how the data is to be sent to the URL
specified in Action.
With get the form data is appended as name / value pairs in the URL string and will look
something like the following:
http://www.servername.com/processpage.php?person=fred&age=35
In the above example:
Name Value
person fred
age 35
The get method that uses appended name / value pairs is limited to around 3000 characters
and also appears in the web browser address bar which means the data is not really secure.
On the other hand the post method embeds the data in the http request for the page and
hence the data is not displayed on the address bar. Also, there is no limitation for the data
length.
So a form consists of the <form> … </form> elements and then a number of input data
boxes, checkboxes, radio buttons, dropdown lists and a submit button. The person enter in
their data into the form, clicks on the submit button which then sends the data to a script
on the server where it is actioned.
Dreamweaver and Forms
When working with Dreamweaver we can insert Form elements using the menu system.
If we select:
Insert -> Form
then we can select the element from the list.
Form elements
Form elements consist of a form element type which defines the type of the input field.
This will be “text”, “checkbox” and so on. Then there will be name which defines the
name of the data field. Optionally there will be a value which is the default value of the
input box.
The main form elements are as follows:
[1] Text
[2] Password
[3] Hidden
[4] Textarea
[5] Checkbox
Check boxes are not dependent on other checkboxes so if there are a number of
checkboxes you can check as many as you want.
[6] Radio Button
Radio buttons are dependent on each other which is different to a check box. In the above
example you can only select Yes or No and not both. Note that the name is the same in
each radio button to show that they are grouped.
This is an HTML 5 input box which validates the email address that has been entered.
There are a number of other HTML 5 specific input boxes and we will look at a few more
further on.
[11] Image Button
Form Controls
[1] To illustrate the form controls, create a new web page called form.html
[2] In the body of the page enter:
</form>
[3] Inside the <form> … </form> add in a radio button:
<p>Gender</p>
<p>
<input name=“gender” type=“radio” value=“Male” />
<input name=“gender” type=“radio” value=“Female” />
</p>
Note that with radio buttons you can only select one item and this is controlled by using
the same name. In the above example the name it uses is “gender”.
[4] Display the page in the browser to see the effect of a radio button.
[5] Add in a drop down list:
<p>Age</p>
<p>
<select name=“age”>
<option value=“0”>Make a selection</option>
<option value =“1”>Under 18</option>
<option value =“2”>18 to 25</option>
<option value =“3”>26 Upwards</option>
</select>
</p>
[6] Display the page in the browser to see the effect of the drop down list.
[7] Add in a submit button.
<input type=“submit” name =“submit” value=“submit” />
Code file: 13_Forms/files/form.html
You might want to add on any other form elements and see how they work.
Example HTML email form
Create a new HTML 5 web page called mail.html
The purpose of this form is to post data to a PHP page that has already been created on a
remote server. The user goes to the mail.html form, enters various details and when they
press the submit button, the data is posted to the PHP page. The PHP page then processes
the data and in this case sends an email to you.
Within the <body> of the web page create a form section on the page similar to the
following:
</form>
Note that the action is the url where the PHP script is located. I have include a PHP script
that can be used in this example but you will need a web server that has PHP and which
sends emails.
[1] Add in a text box for the name, use a name of name
<form action=”….” method=“post”>
Name:<br>
<input type=“text” name=“name” value=“your name”><br>
</form>
[2] Add in a text box for the email address, use a name of toaddress
[3] Add in a textarea for the comments, use a name of comment:
<form action=”….” method=“post”>
Name:<br>
<input type=“text” name=“name” value=“your name”><br>
To address:<br>
<input type=“text” name=“toaddress” value=“your email”><br>
Comment:<br>
<input type=“text” name=“comment” value=“your comment” size=“50”> <br><br>
</form>
[4] Add in a submit button, use a value of Send and a name of submit
[5] Add in the Reset button
[6] Add a hidden field with a name of fromaddress
Your page should look similar to the following:
<!DOCTYPE html>
<html>
<body>
<h3>Send e-mail to [email protected]:</h3>
<form action=”….” method=“post”>
Name:<br>
<input type=“text” name=“name” value=“your name”><br>
To address:<br>
<input type=“text” name=“toaddress” value=“your email”><br>
Comment:<br>
<input type=“text” name=“comment” value=“your comment” size=“50”><br><br>
<input type=“submit” value=“Send” name=“submit”>
<input type=“reset” value=“Reset”>
<input type=“hidden” name=“fromaddress” value=“[email protected]”><br>
</form>
</body>
</html>
Code file: 13_Forms/files/mail.html
Note that the hidden field has been added to define the “from” address. CHANGE THIS
ENTRY TO A SUITABLE FROM EMAIL ADDRESS.
Display the page in your browser, fill in the form and submit the details.
The following php file is a simple email processing script that can be used with this
example. You will need to upload it to a web server to allow an email to be sent.
<?php
//––––––––—
if ( isset($_POST[“name”]) )
{
$name = $_POST[“name”];
}
else
{
echo(“Fill in your name”);
exit();
}
//––––––––—
if ( isset($_POST[“toaddress”]) )
{
$toaddress = $_POST[“toaddress”];
}
else
{
echo(“Fill in the to address”);
exit();
}
//––––––––—
if ( isset($_POST[“fromaddress”]) )
{
$fromaddress = $_POST[“fromaddress”];
}
else
{
echo(“There is no from email address”);
exit();
}
//––––––––—
if ( isset($_POST[“comment”]) )
{
$comment = $_POST[“comment”];
}
else
{
echo(“Enter your comment”);
exit();
}
//––––––––—
if ( isset($_POST[“submit”]) )
{
$submit = $_POST[“submit”];
if ($submit == “Send”)
{
//Send email
$result = “Your name: ” . $name . “ Your comments: “. $comment;
$headers .= “From:” . $fromaddress . “\r\n”;
//$headers = “From: [email protected]\r\n”;
mail( $toaddress, “Comments”, $result, $headers );
echo(“TO ADDRESS : $toaddress<br/>”);
echo(“FROM ADDRESS : $fromaddress<br/>”);
}
}
?>
Code file: 13_Forms/files/processform.php
Issues with email forms
All input boxes must be validated to check that sensible data is being submitted. This is
often done with JavaScript on the client code, and PHP on the server. It is important to
have server side validation as well as client side validation.
Forms may need a CAPTCHA script added to make sure that the form is being submitted
by a real person. A CAPTCHA script is often a display with a text box where you enter in
some characters to prove that you are a human rather than some sort of automated script.
Most forms need server side code for them to be of any value. You can create forms
which just do calculations in JavaScript. However, you may want data to be stored in a
database or you may want to send an email and that can only be done with coding on the
server using PHP or some other programming language such as dot net.
Client side form validation is an extensive subject but there are many systems around now
such as JQuery that make form validation easier for a Web Developer to work with.
Forms in HTML 5
HTML 5 has added a number of new form fields. However, the support of the new fields
is quite patchy on different browsers, and so it may be a few years before we are able to
use them to any extant.
We have shown that standard HTML has form fields for text, radio buttons, checkboxes,
drop down lists, password and hidden fields.
HTML 5 has extended these to include the following:
· email - entry of an email address.
· url – entry of a URL.
· number – number entry with range.
· tel – telephone number
· date – calendar date picker
and so on.
Using these input types makes form validation much easier.
On devices such as smart phones and tablets, these fields are displayed to allow easier
input for the small screen.
The above input types are used as follows:
<input type=”date” name=”date” />
which would be how you use the date input field.
HTML 5 also adds in some validation methods built into the text box themselves.
HTML 5 and form validation
HTML 5 includes a number of extra attributes that can be used to validate form entry on
the client bowser. Not all browses support all the features and also, validation should also
be done on the server as well using a programming language like PHP or dot net.
<!doctype html>
<html>
<head>
<meta charset=“utf-8”>
<title>Untitled Document</title>
</head>
<body>
<form method=“post” action=””>
<fieldset>
<legend>Contact Details</legend>
<p>
<label for=“Name”>Name:</label>
<input type=“text” name=“Name” required />
</p>
<p>
<label for=“Email”>Email:</label>
<input type=“email” name=“Email” required />
</p>
<p>
<label for=“Start Date”>Start Date:</label>
<input type=“date” name=“startdate” required />
</p>
<p>
<input type=“submit” name=“Submit” />
</p>
</fieldset>
</form>
</body>
</html>
Code file: 13_Forms/form_required.html
When this is run in the browser, and you press submit, notice the affect. There will be
differences in the behaviour with different browsers.
<p>
<label for=“age”>Your Age</label>
<input type=“number” name=“age” min=“18” max=“99” value=“21”>
</p>
Code file: 13_Forms/files/form_required_number.html
form_with_styles.html is the same form but with styles added into the document.
Code file: 13_Forms/files/form_with_styles.html
Formatting Forms in HTML 5
HTML 5 has the fieldset, legend and label elements specifically for laying out forms.
Labels are a way of improving usability to a web page. The label is often used to create
the name for the <input> element similar to the following:
<label for=“name”>Your Name</label>
<input type=“text” name=“name” value=“your name”>
The label element does not in itself display anything special for the user.
The label can be bound to an element by using the “for” attribute, or by placing the
element inside the <label> element.
The fieldset provides a way to break up a form into sections and legend is used to title a
fieldset.
Create a new HTML 5 web page called form_format.html and in the body of the page
either copy the following or create the elements by typing them in manually:
<style type=“text/css”>
body {
font-family:Arial, Helvetica, sans-serif;
}
fieldset {
width:500px;
}
fieldset p {
margin: 10px;
padding-bottom:10px;
width:460px;
clear:both;
}
.title {
float:left;
width:100px;
text-align:right;
padding-right:10px;
}
.submit {
text-align:left;
margin: 10px;
}
legend {
font-size:20px;
}
</style>
Test the web page out in different browsers and note the difference in displays. You may
find that IE displays a little different to Chrome
Code file: 13_Forms/files/form_format.html
Field Description
This is what the final display will look like:
<div id=“footer”>
</div>
would be used as a footer.
HTML 5 has introduced a number of schematic Mark-up tags which expresses the
meaning and purpose more clearly to the developer. These elements have names such as
<header>, <footer> and so on. Some of the semantic HTML 5 elements are:
<header> ….. </header>
<footer> ….. </footer>
<section> ….. </section>
<article> ….. </article>
<aside> ….. </aside>
<nav> ….. </nav>
<figure>…. </figure>
<figcaption>….</figcaption>
You do not have to use these in an HTML 5 web page; you can still use DIVs for the
structure as before if you want.
You still have to apply styles to these elements in the same way as you do with DIVs but
you would have something like:
footer
{
padding:5px;
text-align:center;
font-weight:bold;
}
Headers <header> and footer <footer>
The <header> and <footer> elements are used at the top or bottom of each web page but
can also be used as header and footer of individual <article> and <section> elements. For
example, in a blog, a blog post could be an article element and each blog post could have
its own header and footer element.
Navigation <nav>
The <nav> element is used for the major navigation elements of a web page.
Article <article>
The <article> element is used to define content that can be considered as standalone
information such as a comment or a blog post or an item for sell.
Aside <aside>
The <aside> element can be placed inside an article element in which case it should have
content that relates to the article but is not an essential part of the article. It can also be
used outside of an article element, in which case it should contain content that is related to
the entire web page.
Section <section>
The <section> element is a grouping of different sections of a web page, so there may be
sections of news, products, comments, blogs and so on.
Heading groups <hgroup>
The <hgroup> element is used to group together headings <h1> to <h6> and its purpose is
when you have a heading and then a subheading.
Figures <figure> and <figcaption>
The <figure> element is for content of images, videos and so on. The figure caption
<figcaption> is a text description of the image.
Section elements <div>
The <div> element is used where there is no HTML 5 schematic mark-up that could be
used in its place. So for example, you might have a DIV element that is a wrapper for the
entire web content.
The htmlshiv code
For internet explorer browsers that are below IE 9, we need to add in a bit of JavaScript
code so that they correctly recognise the HTML 5 schematic mark-up elements. We add
in the following code to the <head> of the web page:
<!—[if lt IE 9]>
<script src=“http://html5shiv.googlecode.com/svn/trunk/html5.js”></script>
<![endif]—>
Exercise in HTML 5 Layout
This is an example of creating an HTML 5 layout which incorporates a number of HTML
5 schematic elements
<div class=“wrapper”>
<header>
<h1>The Olde Tractor Store</h1>
</header>
<section class=“products”>
<article>
</article>
<article>
</article>
</section>
<aside>
</aside>
<footer>
© The Olde Tractor Store
</footer>
</div>
Code file: 14_HTML5_Design/files/index_01.html
This uses the HTML 5 mark up of header, footer, section, article, nav, aside, hgroup,
figure and figcaption.
<style type=“text/css”>
</style>
We have to make all the schematic mark-up styles as display: block. Block level elements
are those that start on a new line and will be the basic building structure of the layout. We
have to define these as block level because older browsers that do not recognise the
HTML 5 elements will treat them as inline elements.
We then create the body style which contains a background image.
header, section, footer, aside, nav, article, figure, figcaption {display: block;}
body {
color:#514F4F;
background-color: #f9f8f6;
background-image: url(“images/lgren033.jpg”);
background-position: center;
font-family:Arial, Verdana;
line-height: 1.3em;
margin: 0px;}
Code file: 14_HTML5_Design/files/index02.html
.wrapper {
width: 960px;
margin: 10px auto 10px auto;
border: 2px solid #000000;
background-color: #ffffff;}
header {
height: 160px;
background-image: url(“images/tractorheader.jpg”);}
Code file: 14_HTML5_Design/files/index03.html
h1 {
text-indent: -9999px;
width: 960px;
height: 130px;
margin: 0px;}
In this example, the h1 tag has been set with a text-index of -9999px. This is so that the
text itself is shifted off the screen to the left , but will still be available for text screen
readers. The header image tractorheader.jpg displays the same text.
Code itle: 14_HTML5_Design/files/index04.html
<div class=“wrapper”>
<header>
<h1>The Olde Tractor Store</h1>
<nav>
<ul>
<li><a href=”” class=“current”>HOME</a></li>
<li><a href=””>SPARES</a></li>
<li><a href=””>FAIRS</a></li>
<li><a href=””>ABOUT</a></li>
<li><a href=””>CONTACT</a></li>
</ul>
</nav>
</header>
<section class=“products”>
<article>
<figure>
<img src=“images/masseyferg_290.jpg” alt=“Tractor” />
<figcaption>1979 Massey Ferguson 575</figcaption>
</figure>
<hgroup>
<h2>1979 Massey Ferguson 575</h2>
<h3>£4,500 Plus VAT</h3>
</hgroup>
<p>1979 Massey Ferguson 2wd Tractor with muti-power, comes with MF loader (not fitted), done 5555 hours,
with PUH and 2 double spool valves, overall in resonable condition for its age.</p>
</article>
<article>
<figure>
<img src=“images/ford_290.jpg” alt=“Tractor” />
<figcaption>Fordson Major 6 Cylinder, 90HP</figcaption>
</figure>
<hgroup>
<h2>Fordson Major 6 Cylinder, 90HP</h2>
<h3>£2,650 Plus VAT</h3>
</hgroup>
<p>This has had a Ford 6 cylinder fitted and repainted a while ago. Starts, runs and drives well, very useful to run
a grain blower, or other stationery P.T.O. application.</p>
</article>
</section>
<aside>
<section class=“spares-list”>
<h2>Spares Needed</h2>
<a href=””>Starter Motor - Perkins Engine</a>
<a href=””>Radiator - David Brown</a>
<a href=””>McCormick CX100 Filter Kit</a>
<a href=””>Case IH Clutch Kit</a>
</section>
<section class=“contact-us”>
<h2>Contact</h2>
<p>The Olde Tractor Store<br />
The Warehouse<br />
Chippenham<br />
Wiltshire SN15 2JP</p>
</section>
</aside>
<footer>
© The Olde Tractor Store
</footer>
</div>
Code file: 14_HTML5_Design/files/index05.html
nav, footer {
clear: both;
color: #ffffff;
background-color:#42573C;
height: 30px;}
nav ul {
margin: 0px;
padding: 5px 0px 5px 30px;}
nav li {
display: inline;
margin-right: 40px;}
nav li a {
font-weight:bold;
color: #ffffff;}
nav li a:hover, nav li a.current {
color:#FB9294;}
Code file: 14_HTML5_Design/files/index06.html
<section class=“products”>
<article>
</article>
<article>
</article>
</section>
Add in the styles for the section and article elements:
section.products {
float: left;
width: 669px;
border-right: 1px solid #eeeeee;}
article {
clear: both;
overflow: auto;
width: 100%;}
Code file: 14_HTML5_Design/files/index07.html
hgroup {
margin-top: 40px;}
figure {
float: left;
width: 290px;
height: 220px;
padding: 5px;
margin: 20px;
border: 1px solid #eeeeee;}
figcaption {
font-size: 90%;
text-align: left;}
Code file: 14_HTML5_Design/files/index08.html
aside {
width: 240px;
float: left;
padding: 0px 0px 0px 20px;}
aside section a {
display: block;
padding: 10px;
border-bottom: 1px solid #eeeeee;}
aside section a:hover {
color: #985d6a;
background-color: #efefef;}
aside h2 {
padding: 30px 0px 10px 0px;
color: #de6581;}
Code file: 14_HTML5_Design/files/index09.html
TASK 11 - Add in the final group of styles to finish off the links, h tags
and footer
a {
color: #de6581;
text-decoration: none;}
h1, h2, h3 {
font-weight: normal;}
h2 {
line-height:1.2em;
margin: 10px 0px 5px 0px;
padding: 0px;}
h3 {
margin: 0px 0px 10px 0px;
color: #de6581;}
footer {
font-size: 80%;
padding: 8px 0px 0px 20px;}
Code file: 14_HTML5_Design/files/index10.html
<!—[if lt IE 9]>
<script src=“http://html5shiv.googlecode.com/svn/trunk/html5.js”></script>
<![endif]—>
Summary
This Chapter has looked at how to work with HTML 5 layout elements. These provide a
way to define the page layout using named elements which more clearly represent the
structure of a page. HTML 5 is the standard that we should use for all our pages from
now on and provide new elements and attributes particularly for multimedia and graphics.
15
Responsive Web Design (RWD)
What’s in this chapter:
* Description of RWD.
* Media queries
* An example RWD framework.
Responsive web design (RWD) is the ‘in thing’ at the moment.
If we go back a few years we only had one way to display web pages which was using a
VDU. These were based on the old style Television (TV) sets which used cathode ray
tubes (CRT). These were physically very large and heavy.
With only one type of device to display our web pages on, it was quite acceptable to
design web pages that fitted to a fixed width of say 960px.
Gradually new technology came in which used LCD and LED displays. These displays
became very popular very quickly because they are very thin and light and they use much
less power. It wasn’t long before this new display technology was incorporated in mobile
devices, phones and tablets which changed the way we interact with the internet.
So this introduced devices that display at different resolution and on different sizes.
So how do we cope with these different sized devices? There are really two ways to do
this:
[1] Create multiple web sites at different resolution and size and have a script which
redirects to different sites after detecting the device type.
[2] Create one site but different CSS depending on the screen size.
Clearly the second method is preferred as you are not duplicating the content which would
become difficult to maintain.
@media print {
/ * print styles */
}
In addition, and more importantly for response layouts, we can have specific styles based
on the view port size. In the example below we can see that we can use different images
based on the screen size.
@media screen {
#firstimage {
background-image: url(/graphics/firstimage980.jpg);
height:100px;
}
}
@media screen and (max-width: 980px) {
#firstimage {
background-image: url(/graphics/firstimage980.jpg);
height:100px;
max-width:980px;
}
}
@media screen and (max-width: 650px) {
#firstimage {
background-image: url(/graphics/firstimage650.jpg);
height:95px;
max-width:650px;
}
}
@media screen and (max-width: 480px) {
#firstimage {
background-image: url(/graphics/firstimage480.jpg);
height:80px;
max-width:480px;
}
}
@media screen and (max-width: 320px) {
#firstimage {
background-image: url(/graphics/firstimage320.jpg);
height:60px;
max-width:320px;
}
}
@media screen and (max-width: 240px) {
#firstimage {
background-image: url(/graphics/firstimage240.jpg);
height:50px;
max-width:240px;
}
}
As an example to show how the @media query can change the styles for different
viewports:
<!doctype html>
<html>
<head>
<meta charset=“utf-8”>
<title>Responsive example</title>
<style type=“text/css”>
@media (min-width: 500px) and (max-width: 600px) {
h1 {
color: fuchsia;
}
}
</style>
</head>
<body>
<h1>This demonstrates the way that styles can change as the size of the page changes.</h1>
</body>
</html>
Code file: 15_Responsive_Design/files/responsive/responsive.html
So first display the page in your browser and then change the size of the browser. As you
reduce the size down to 600px, the color of the <h1> tag will change. Then as you reduce
the size further down to under 500px, the color of the </h1> tag changes back.
A Responsive Web Design Framework example
In this exercise we are going to create a web site using the Responsive Web Design
Framework HTML-KickStart which can be download from:
http://www.99lime.com/
We will use this framework as it described as ‘light weight’ and is not as extensive as
others. There are other similar frameworks which are available, in particular, Twitter
bootstrap which is located at http://getbootstrap.com/
Another one is called http://foundation.zurb.com/
All of these frameworks are all open source and free to use.
Google also has a web template system at https://developers.google.com/web/starter-kit/?
hl=en
NOTE: if you are using Internet Explorer, in the “Compatibility View Setting”, make
sure that “Display internet sites in Compatibility View” is unticked.
Microsoft created the compatibility view for Internet Explorer 8 to give web designers
time to convert their pages over from the non-standard techniques used in IE 7 and IE 6, to
a more web standard compliant version. It tells the browser to render the page as if it were
IE version 7 rather than IE version 8.
We are going to create another version of the Archibald’s web site which we did in an
earlier chapter. You will find that this version will look better and it will be easier to
maintain because it uses a grid system.
<div class=“grid”>
<div id=“header” class=“col_12”>
Header menu
</div>
<div id=“blocks” class=“col_12”>
<div id=“description” class=“col_12”>
<div class=“col_6”>
Description
</div>
<div class=“col_6”>
Image
</div>
</div>
</div>
Code file: 15_Responsive_Design/files/responsive/index_task4.html
<style type=“text/css”>
</style>
Code file: 15_Responsive_Design/files/responsive/index_task6.html
Code file: 15_Responsive_Design/files/responsive/index_task7.html
#header a:link {
color:#fff;
text-decoration: none;
}
#header a:visited {
color:#fff;
text-decoration: none;
}
#header a:hover {
color: #ff0000;
}
Code file: 15_Responsive_Design/files/responsive/index_task8.html
#logo{
background-color:#000;
width:100%;
margin-left:0;
margin-bottom:0px;
}
#logo h1{
font-family: ‘Fredoka One’, cursive;
color:#FFFFFF;
font-size:300%;
padding-left:100px;
}
Code file: 15_Responsive_Design/files/responsive/index_task9.html
Code file: 15_Responsive_Design/files/responsive/index_task10.html
#blocks h1 {
font-size: 170%;
color: red;
text-align: center;
}
Code file: 15_Responsive_Design/files/responsive/index_task12.html
<picture>
<!—[if IE 9]><video style=“display: none;”><![endif]—>
<source srcset=“shop02.jpg” media=”(min-width: 1024px)”>
<source srcset=“shop03.jpg” media=”(min-width: 480px)”>
<!—[if IE 9]></video><![endif]—>
<img srcset=“shop03.jpg” alt=“Shop”>
</picture>
NOTE: The media tag is defining what size browser will be displayed.
NOTE: The picture tag is not available in IE and so when this is displayed in IE, no
image will appear. To overcome this we use the picturefill.js script which enables support
for the picture element and associated features in browsers that do not yet support them.
<script>
//old ie script
document.createElement( “picture” );
</script>
<script src=“js/picturefill.js” async=“true”></script>
Place the above script into the <head> of the web page pointing to the JavaScript in the js
folder. This should make the <picture> element work in IE and in any other browser that
does not support the picture element.
Code file: 15_Responsive_Design/files/responsive/index_task14.html
TASK 15 - Styles for description
#description h1 {
font-size: 170%;
color: red;
text-align: center;
}
#description p {
font-size: 110%;
}
Code file: 15_Responsive_Design/files/responsive/index_task15.html
#openinghrs h1 {
font-size: 170%;
color: red;
text-align: center;
}
Code file: 15_Responsive_Design/files/responsive/index_task17.html
#refs {
background-color: black;
color:white;
margin-top: 20px;
margin-bottom: 20px;
padding-bottom: 20px;
padding-top: 20px;
text-align: center;
}
Code file: 15_Responsive_Design/files/responsive/index_task19.html