spacer

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

home / programming / css_style / 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

Search
The Business Internet

Developer News
MicrosoftÂ’s Automated Agent: Can We Talk?
Borland Finally Sells CodeGear
Red Hat Heads For The JON 2.0

How to Style a Definition List with CSS

By Stu Nicholls.

Introduction

Most tutorials on the styling of CSS lists for menus use unordered lists, which, for people starting out with CSS, can be a little difficult to grasp as the use of unordered lists requires extra styling to remove the bullets.

In this tutorial I demonstrate how to style a Definition List, which is equally suitable for menus, but is a little easier to understand.

Here's how to begin, using the following Definition List ...

...and, with the minimum amount of extra code and a little CSS, end up with a stylish menu like this, which incidentally does not use any graphics:

Styled Definition List

Method

Step 1

The Definition List (X)HTML

The basic Definition List source code is shown below:

<dl id="gallery">
  <dt>
    Art Gallery
  </dt>
  <dd>
    <a href="#nogo" title="Paul Cezanne">
      Paul Cezanne
    </a>
  </dd>
  <dd>
    <a href="#nogo" title="Henri Matisse">
      Henri Matisse
    </a>
  </dd>
  <dd>
    <a href="#nogo" title="Vincent van Gogh">
      Vincent van Gogh
    </a>
  </dd>
  <dd>
    <a href="#nogo" title="William Turner">
      William Turner
    </a>
  </dd>
  <dd>
    <a href="#nogo" title="John Constable">
      John Constable
    </a>
  </dd>
  <dd>
    <a href="#nogo" title="Claude Monet">
      Claude Monet
    </a>
  </dd>
</dl>

To add the curved corners and the white border we need to use an outer containing div and a group of <b></b> tags at the beginning and the end of the containing div.

Our finished Definition List source code will then look like this:

<div id="container">
  <b class="top">
    <b class="b1"></b>
    <b class="b2"></b>
    <b class="b3"></b>
    <b class="b4"></b>
  </b>
  <dl id="gallery">
    <dt>
      Art Gallery
    </dt>
    <dd>
      <a href="#nogo" title="Paul Cezanne">
        Paul Cezanne
      </a>
    </dd>
    <dd>
      <a href="#nogo" title="Henri Matisse">
        Henri Matisse
      </a>
    </dd>
    <dd>
      <a href="#nogo" title="Vincent van Gogh">
        Vincent van Gogh
      </a>
    </dd>
    <dd>
      <a href="#nogo" title="William Turner">
        William Turner
      </a>
    </dd>
    <dd>
      <a href="#nogo" title="John Constable">
        John Constable
      </a>
    </dd>
    <dd>
      <a href="#nogo" title="Claude Monet">
        Claude Monet
      </a>
    </dd>
  </dl>
  <b class="bottom">
    <b class="b4"></b>
    <b class="b3"></b>
    <b class="b2"></b>
    <b class="b1"></b>
  </b>
</div>

This is all that is needed to be added to the Definition List source code.

If you don't want the curved corners then leave out the "top" and "bottom" classes.

Step 2

Now that we have the definition list in a suitable format, I'll take you through the various stages of styling

Firstly and most importantly, make sure that you have the correct (X)HTML !DOCTYPE. Without this most browsers will be thrown into 'quirks' mode which will lead to all sorts of incompatibility problems. W3C QA - List of valid DTDs has a list of valid DOCTYPES that can be used. Select from XHTML1.0 or XHTML1.1 as these are more suitable for this styling. I use XHTML1.1 for all my current web pages.

The definition list with NO styling will appear as below:

Step 2

Step 3

Styling the body tag

body {
  font-family:arial, verdana, sans-serif; 
  font-size:0.8em; 
  background:#8be; 
  color:#fff;
  }

The body style sets the font to arial as first choice, verdana as second choice and the generic sans-serif as default (you should always set a default generic font as the final choice in the font-family list). The default font size is set in ems to allow the text size to be user selectable. This menu can be infinitely resized and it will always stay in shape.

The background color is pale blue to show off the white border that will be applied to the list. The default text color is white.

Step 3


home / programming / css_style / 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: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
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 >
Software Engineering for Ajax · Perl Pragma Primer · Implement Drag and Drop in Your Web Apps: Part 2
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-FiPlanet Gift Guide, Class of 2008 · Patriot Updates their DDR2 4GB PC2-8500 Line to "Revision 2" · Review: Samsung SCX-4500 Multifunction Printer

Created: March 27, 2003
Revised: May 13, 2005

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