Difference between revisions of "class-design-pattern"

From Microformats Wiki
Jump to navigation Jump to search
m (Reverted edit of 1146321668, changed back to last version by MatthiasLuedtke)
(Referenced naming principles)
Line 7: Line 7:
 
* add semantics to (X)HTML by using [http://www.w3.org/TR/REC-html40/struct/global.html#adef-class class names].  The <code>class</code> attribute is a space sepearted list of class names.
 
* add semantics to (X)HTML by using [http://www.w3.org/TR/REC-html40/struct/global.html#adef-class class names].  The <code>class</code> attribute is a space sepearted list of class names.
 
* if an appropriate semantic element is not available, use <code>span</code> or <code>div</code>.
 
* if an appropriate semantic element is not available, use <code>span</code> or <code>div</code>.
 +
* always choose names following the [[naming-principles|microformats naming principles]].
  
 
== Description ==
 
== Description ==

Revision as of 20:17, 9 December 2006

Class design pattern

Purpose

Use the class-design-pattern to indicate semantic meaning about XHTML elements

How to use it

  • add semantics to (X)HTML by using class names. The class attribute is a space sepearted list of class names.
  • if an appropriate semantic element is not available, use span or div.
  • always choose names following the microformats naming principles.

Description

This is one of the most frequently occurring design patterns in microformats. Semantic meaning can be indicated on XHTML content by using the class attribute of an enclosing element. For example, hCard 1.0 adds information indicating that certain elements are a vCard URL, a Full Name and Organization by the class design pattern:

<div class="vcard">
 <a class="url fn" href="http://tantek.com/">Tantek Çelik</a>,
 <span class="org">Technorati</span>
</div>

Note especially the preceding example:

  • the section of the XHTML document that the microformat is being applied to is defined by class="vcard". This is very common among non-trivial microformats.
  • the use of both inline (<a> and <span>) and block (<div>) level elements. This provides the microformat designer with a range of options for inserting semantic information without interfering with existing presentation
  • the use of multiple class names on a single element (such as "url fn"). This allows:
    • single elements to have multiple meanings
    • allows adding semantics to existing presentation

See Also