spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / css_frames / 1 current pageTo page 2To page 3
[next]

ASP 3.0/.NET Developer
Jupitermedia
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
SaaS Tool Offers Custom Database Development
Microsoft’s Automated Agent: Can We Talk?
Borland Finally Sells CodeGear

How to Create a Frames Layout with CSS

By Stu Nicholls.

Introduction

By far the most sought after use of CSS is to emulate the dated html 'frame' layout, whereby the header, navigation and footer stay on screen at all times and the content area will scroll. Since the adoption of the fixed position style by the latest browsers this is quite an easy task for CSS. Unfortunately, Internet Explorer hasn't introduced this style into it's repertoire (perhaps IE7 will correct this deficiency when it's released later this year).

Fortunately, there are ways around this and it's possible to make Internet Explorer versions IE5.01, 5.5 and 6 fall into line with the rest.

The following article will detail how to set up a 'frame' style layout with a fixed header, which can incorporate the navigation, a fixed footer and a scrolling content area, all of which will resize down to virtually nothing and still be usable (with scroll bars added as required). It has been tested on PC browsers Mozilla 1.7.5, Netscape 7.1, FireFox 1.0.3, Opera 8, Internet Explorer IE5.01, IE5.5 and IE6 and also Mac browsers Safari (1.3) and FireFox (1.0.3).

Method

Step 1

The (X)HTML setup

The layout I am aiming for will have a header the full width of the browser window that is 120px high and a footer the full width of the browser window by 50 px high. The header and footer will be fixed to the top and bottom of the browser window and the space in between will hold the scrolling content.

An example of the layout can be seen here.

Proposed layout

Since Internet Explorer doesn't recognize position fixed we need to make use of another 'bug' which will allow us to use an alternative method. This bug is the well known and documented faulty box model whereby the size of a box includes the padding and border (more on this later).

In order to make use of the faulty box model and still write valid code we need to use the following code at the start of our (X)HTML.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<title> A CSS Frame Layout </title>
<meta name="Author" content="Stu Nicholls" />
<style type="text/css">

</style>
</head>

<body>


</body>
</html>

Note the first line - <?xml version="1.0" encoding="UTF-8"?> - is valid (X)HTML and will not affect other browsers, but will have the effect of switching Internet Explorer into 'quirks' mode. If you want Standards Compliant Mode in Internet Explorer 6 the FIRST line has to be the !DOCTYPE declaration. Using the first line as above will give us valid code and the faulty box model.

Step 2

Styling the body tag

We do NOT need to style the <html> tag

body {
  margin:0;
  border:0;
  padding:0;
  height:100%; 
  max-height:100%; 
  background:#eee; 
  font-family:arial, verdana, sans-serif; 
  font-size:76%;
  overflow: hidden; 
  }

The body styling

margin:0; - removes the body margin.

border:0; - removes the body border.

padding:0; - removes the body padding.

The above styling just gives us the whole window to work with.

height:100%; - sets the height of the browser window to 100%

max-height:100%; - ensures that the body is not larger than 100% - This is for all browsers except Internet Explorer.

background:#eee; - sets the body background to light grey (choose any color you like).

font-family:arial, verdana, sans-serif; - select your fonts for the page. Note: You should always end the list with a generic font.

font-size:76%; - select a basic font size for the page. I find that 76% works well in all browsers.

overflow: hidden; - this has the effect of hiding the scroll bars in Internet Explorer.

Now we have a blank canvas with which to work. It will not scroll and doesn't have scroll bars.

Step 2

Here there's not much to see except a blank, gray window.


home / programming / css_frames / 1 current pageTo page 2To page 3
[next]



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: 7.0, Microsoft's Lucky Version?
Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Windows Server 2008
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES
webref The latest from WebReference.com Browse >
How to Create an Ajax Autocomplete Text Field: Part 6 · Software Engineering for Ajax · Perl Pragma Primer
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Using File Virtualization for Disaster Recovery · VoIP Security: SIP—Versatile but Vulnerable · Around the World in 80 Nodes

Created: March 27, 2003
Revised: April 26, 2005

URL: http://webreference.com/programming/css_frames/1