Difference between revisions of "class-design-pattern"
m (Changed protection level for "class-design-pattern" [edit=sysop:move=sysop])
Latest revision as of 08:39, 7 April 2013
Class design pattern
How to use it
- always use the most appropriately semantic (X)HTML element for the content. if an appropriate semantic element is not available, use
div. always avoid presentational (X)HTML.
- add semantics to (X)HTML by using semantic class names. The
classattribute is a space separated list of class names.
- always choose names following the microformats naming principles.
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 adds information indicating that certain elements represent vCard person or organization, its URL, Formatted 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 in particular:
- 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