HTML and CSS basics

Objectives

Ajax

Basic web page template (HTML5)

For this course, we will use HTML 5 as our standard. A lot of the new features are not implemented across all the browsers yet, but we can get started by using the HTML 5 template and using some of the more commonly implemented new features. Since the head element is processed before the body element, it is common to move the script tags to the bottom of the document so they come just before the closing body tag. This can help make a page appear to load faster since content starts appearing sooner.

<!DOCTYPE html> <html lang="en"> <head> <title>Title of page</title> <meta charset="utf-8"> <link rel="stylesheet" href="style1.css"> <style> /* style rules go here */ </style> <script src="js1.js"></script> </head> <body> This is where the displayable content goes. </body> </html>

Structure of a tag

We will review whatever HTML tags we need as they are encountered in class. The basic structure tags for elements with and without content is given below:

HTML comments

<!-- comment (may be multiline) -->

Making Internet Explorer work better

Add the following in the "head" element to help versions of Internet Explorer prior to version 9 work better by adding in some standard elements and styling.

<!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]-->

Reset CSS

Browsers may have some inconsistencies in the way they display certain elements. Those inconsistencies can be reduced by including a set of CSS rules that resets everything to a base standard. These rules must be placed before all other CSS rules in your document. Eric Meyer has written a great CSS reset tool which he has posted on his website meyerweb.com. One technique you can use is to store Eric Meyer's Reset CSS tool locally and then included it as the first set of CSS rules as a link in your web page template.

Very brief review of CSS

How it all fits together

Completed template

The completed template with the html5shiv link and Eric Meyer's reset (stored locally) is shown below. This template assumes all JavaScript and CSS will be stored in separate files. The template also assumes that the CSS and JavaScript files will be stored in theor own directories.

<!DOCTYPE html> <html lang="en"> <head> <title>Title of page</title> <meta charset="utf-8"> <!-- documentation comments --> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link rel="stylesheet" href="css/reset.css"> <link rel="stylesheet" href="css/style1.css"> </head> <body> <div>Content of template document.</div> <script src="scripts/js1.js"></script> </body> </html>