We present some ideas on user interface design and implementation in Web applications, in particular using Smarty and CSS.
Here are some notes based on Marilyn Ford's old (PowerPoint) slides for 2505ICT User Interface Design. (I don't guarantee that my links are correct.)
See 2505ICT Lesson 5 - Prototypes - PowerPoint slides.
See 2505ICT Lesson 6 - Layouts - PowerPoint slides.
See 2505ICT Lesson 7 - Colour and Typography - PowerPoint slides.
When performing usability testing, consider the following issues:
ISO 13407: "The usability of an interface is a measure of the effectiveness, efficiency and satisfaction with which specified users can achieve specified goals in a particular environment with that interface."
See 2505ICT Lesson 8 - Usability testing - PowerPoint slides.
There is widespread agreement between popular Web site developers about page layout. See, e.g., amazon.com, apple.com, ebay.com, facebook.com, flickr.com, google.com, microsoft.com, nab.com.au, telstra.com, twitter.com, wikipedia.com, yahoo.com. They all have the following structure:
Look again at examples of popular Web sites to convince yourself of the ubiquity of this practice.
All developers should therefore follow this standard practice for page layout.
Common practice is different on small screens, particularly on smartphones. There, the practice is single column, one-line header, content, then navigation and footer.
Layouts may be fixed-width or fluid. Many popular Web sites use fixed-width layouts, some use fluid layouts, but I believe fluid layouts should be used whenever possible.
There are two possible approaches to providing a uniform appearance across different pages using Smarty.
Each page view in the application should be a template of the following form:
<!DOCTYPE html>
<html>
<head>
<title>Title of this particular page</title>
<link rel="stylesheet" type="text/css" href="styles/style.css">
...
</head>
<body>
{include file="header.tpl"}
{include file="navigation.tpl"}
<section class="content"}
Content of this particular page...
</section>
{include file="footer.tpl"}
</body>
</html>
This approach has the advantage that every template is a complete HTML document, with inclusions. It ensures that the common elements (header, sidebar and footer) are identical on every page.
It has the disadvantage that all templates contain some common content.
(The included templates, header.tpl, etc., should be in the
same templates directory as the main templates.)
All modern template systems allow one template to inherit content from a parent page in an object-oriented fashion. This allows us to put all common elements into a single page, and to provide child pages that only contain content specific to that particular page.
So, from Smarty 3, we can write a parent template,
template.tpl, say, that contains the text
of the common header, footer and navigational elements as follows:
<!DOCTYPE html>
<html>
<head>
<title>{block name=title}Generic title{/block}</title>
<link rel="stylesheet" type="text/css" href="style.css">
...
</head>
<body>
...Common header elements...
...Common navigational elements...
<section class="content">
{block name=body}{/block} {* Placeholder for content of different pages *}
</section>
...Common footer elements...
</body>
</html>
The parent template does not have to be called template.tpl;
it can be called layout.tpl, root.tpl, or
whatever (sensible name) you like.
Any particular page, say index.tpl will then extend
the parent page as follows:
{extends file="template.tpl"}
{block name=title}Title of this particular page{/block}
{block name=body}
Content of this particular page...
{/block}
Each named block overrides the block with the same name (which must be present) in the parent page. Note that each particular page only contains content specific to that page.
PHP scripts should display the child pages, e.g.,
index.tpl, and never the common parent page.
Note that child pages may themselves be extended by their children and so on.
Stylesheets are used to specify how headers, navigational elements, content blocks, footers, and their contained elements are displayed.
The two most challenging aspects of page layout using CSS are:
Multicolumn layouts may be implemented using tables (semantically inappropriate and inefficient), frames (deprecated) and style sheets (recommended and standard practice).
Here is an example (zipped archive) of a two-column layout using nested framesets (from week 2). Note that the height (or width) of frames in a frameset may be specified in pixels (130px), in percentages (75%), or automatically (*).
Framesets have the advantage of being simple and efficient, but have the huge disadvantage that individual pages can not be bookmarked and that they are deprecated (if not obsolete).
Here is a simple example of the same two-column layout as above using CSS floating and positioning. In this case, you must study both the page source and the external CSS file to understand the example.
Here is a more complex example. Again, you need to study both the page source and the external CSS file.
For precise, grid-based layout it's important to be familiar with the CSS box model as summarised at w3schools.com. This model distinguishes between an element's content (specified by height and width attributes) and surrounding padding, border and margin spacing.
Another good introduction to the CSS box model and positioning is in this HTML and CSS guide.
Specification of two- and three-column layouts using style sheets requires a good understanding of CSS positioning.
This is described in Chapter 24 of Web Design in a Nutshell, 3rd edition by Neiderst Robbins and also at w3schools.com.
The best online description of CSS positioning that I know is CSS Positioning 101 by Noah Stokes on the excellent A List Apart Web site. It very carefully describes the difference between static, relative, absolute, fixed and inherit positioning.
Here is simple example from this article that illustrates a fixed footer and here is a more complex example.
Exercise. Write a page with a fixed left column and a scrolling right column. Hint. The left column should have fixed position and the right column should have relative position.
It's also important to understand CSS float. The best online description of this topic that I know is CSS FLoats 101 on A List Apart. Again, see also w3schools.com.
Other older, more complex, online descriptions of CSS layout are In Search of the Holy Grail and The Holy Grail Refactored.
Multicolumn layout approaches can be combined with the use of Smarty templates as described above.
Don't forget to review earlier material on CSS, including the use of
classes (.alert) and ids (#content), the use of
nested patterns (body .special li), etc.
With the growth of Web access from mobile phones and tablets (as well as laptops and desktops), this problem has become more important than ever. How can a developer design a site for such a range of screen sizes?
First, in CSS 2, one can specify alternative style sheets in a document
head, and distinguish them by the media atttribute, with
values all, handheld, print,
projection, screen, and others.
<link rel="stylesheet" type="text/css" media="all" href="styles/basic.css"> <link rel="stylesheet" type="text/css" media="handheld" href="styles/handheld.css"> <link rel="stylesheet" type="text/css" media="screen" href="styles/screen.css"> <link rel="stylesheet" type="text/css" media="print" href="styles/print.css">
Only the stylesheet that matches the media of the client will be loaded.
Now, in CSS 3 (becoming widely implemented), media queries allow finer grained distinctions based on the physical characteristics (e.g., screen size) of the client.
<link rel="stylesheet" type="text/css" media="screen and (max-device-width: 480px)" href="shetland.css" /> <link rel="stylesheet" type="text/css" media="screen and (max-device-width: 480px) and (resolution: 163dpi)" href="orkney.css" />
This allows us to use different stylesheets depending on the physical characteristics of the client.
Designing Web pages that are attractive and usable on devices with very different physical characteristics is very challenging, even if different stylesheets are used for different devices. The technique for achieving this is called (misleadingly?) responsive design. The article Responsive Web Design at A List Part introduces this topic.
Some of the main principles of responsive Web design are:
The book by Marcotte cited above gives a more detailed description.
When specifying layouts for small screens (e.g., mobile phones), the fundamental principle is Content first! I.e., content first, navigation second. This contrasts with the normal layout for large screens, which is to put navigational elements at the top or on the side.
Some developers find this task too difficult, and simply return different
documents to the client depending on the properties of the client
as expressed in the HTTP request. Hence, you may see URLs on your mobile
phone, e.g., of the form m.ebay.com and
m.facebook.com. This has the disadvantage of requiring
the developer to maintain essentially two (or more) different Web sites
(as opposed to two different style sheets).
Users are more important than developers. Therefore: