spacer

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

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

Information Technology Auditor (PA)
Next Step Systems
US-PA-Wayne

Justtechjobs.com Post A Job | Post A Resume
Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

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]

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

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
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
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
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
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
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
Review: Lenovo ThinkPad SL300 · OCZ PC3-10666 Gold 2x1GB Review · Apple Recommends Antivirus for Macs

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

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