spacer

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

home / authoring / style / sheets / multiclass To page 1current pageTo page 3
[previous] [next]

Saving Bytes by Using Multiple CSS Classes on Elements

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

The Current Way

The next major shift came when Cascading Style Sheets began to take off and layers became a popular mechanism for providing layout. CSS Classes were used to handle presentational material. Let us create an example of the typical techniques used with this approach:

View CSS Example 1 (Opens in new window.)

This document weighs in at 1047 bytes and for all intents and purposes renders identically to the tables approach. Quite a savings already! But perhaps a better representation of current thinking would be shifting all style properties to a style sheet in order to separate style from content:

View CSS Example 2 (Opens in new window.)

Shifting all the styles to a style sheet sees the total number of bytes rise to 1139 bytes, an increase over the previous method. However, the advantage here is that all styles are contained in one section, while the content is contained within another section, making the editing of the document far easier. Sometimes you have to lose ground in one area to gain ground in another.

The separation of content from design would typically see the style sheet be linked from the document. However for the purposes of this article, I am presenting the material in one document, so that viewers readily have access to the source code, rather than having to open separate documents.

The New Way

So far I haven't presented anything that hasn't been well advocated in the past, nevertheless it was important to provide some context for what is about to follow.

What is interesting to me is that the newer browsers afford developers techniques that can greatly optimize pages, but as yet haven't made their way into the mainstream of Web development practices.

One such technique is the use of multiple classes on elements. Yes, standards based browsers allow you to apply two or more classes to an element! For example, let's assume we have two custom classes in the style sheet named maintext and center respectively:

.maintext {
   font-family:   "Courier New", Courier, mono;
   font-size:     14px;
   color:         #FFCC99
}

.center {
   text-align:    center;
}

Then what we could do is apply both classes to the same element with the following syntax:

<div id="Layer2" class="maintext center">

The element would render with both classes applied in Internet Explorer 5.0+, Netscape 7+ and Opera 7. But how does this help us when it comes to optimizing the number of bytes used on a page?


home / authoring / style / sheets / multiclass To page 1current pageTo page 3
[previous] [next]

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

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Crucial Triples Up With New Three-Channel DDR3 Kits · Meet the Finalists: Excellence in Technology Awards · Tealeaf Offers Insight to Mobile Customer Behavior

Created: November 27, 2002
Revised: November 27, 2002

URL: http://webreference.com/authoring/style/sheets/multiclass/2.html