Manipulating Definition Lists for Fun and Profit

There is a really groovy photo gallery here. Too bad you can't see it. Go to www.macromedia.com and get the Flash player if you'd like to.

This is part one of a multi-part article on manipulating Definition Lists with CSS and some WordPress Link tricks (don’t ask how many parts yet, we’ll see when I run out of ideas). Even if you don’t use WordPress this article still explores a creative method of rendering Definition Lists in flexible multi-column layouts.

Have you ever wished you had more options or flexibility when it came to marking up WordPress Link Lists? I wanted a WP link list that could display in multiple columns with varying amounts of text, have the text below the image/link, a groovy background, and basically look nothing like your typical list.

If you haven’t been there yet, take a look at my Portfolio page which is marked up using this technique. A lot of my inspiration for this came from Douglas BowmanCSS SlidingDoors which has proved incredibly useful (it also allows my sidebar background to expand dynamically). The Sliding Door idea is that you use two HTML elements, one inside the other, each with half of a graphic, and as they expand or contract the graphic backgrounds slide to adjust for different sizes. Bowman used <li> and <a> in a horizontally expanding menu. I’m using <dt> and <dd> with vertical flexibility.

Marking up WordPress Lists as Definition Lists

If you’ve played around with WP lists you probably used get_linksbyname to display your lists.


<ul>
 <?php get_linksbyname('portfolio', '<li>', '</li>',
  '', TRUE, 'rating', TRUE, FALSE, -1, FALSE); ?>
</ul>

You can see what all the TRUEs and FALSEs are at the WordPress Codex get_linksbyname template tag description. It basically says ‘run through my list and start each item with an opening list element, place a break between the image/link and description, and then close up the list tag.’ This is great, but puts some confines on the display possibilities of the images and descriptions. Nothing says though that you can only use list tags. Try this on for size –


<dl>
  <?php get_linksbyname('portfolio', '<dt>', '</dd>',
   '</dt><dd>', TRUE, 'rating', TRUE, FALSE, -1, FALSE); ?>
</dd>
</dl>

You will end up with a definition list structured like this -


<dl class="portfolio">
  <dt>Image/link 1 </dt>
  <dd> Description 1</dd>
  <dt>Image/link 2 </dt>
  <dd> Description 2</dd>
  <dt>Image/link 3 </dt>
  <dd> Description 3</dd>
</dl>

Now I can control the margins, padding, float, etc. of the description text independently of the images because it is wrapped in its tag. And in case you are wondering where I put my call to get_linksbyname, I created a template named Portfolio with this call on it, and then assigned it to a Page named the same thing. Already pretty cool, but wait–there’s more with this Ginsu knife set.

Styling Fluid Multi-Column Definition Lists

Have you noticed everything in WordPress can look like a list? That’s because they are lists! This is great semantically, but starts to look tired to me. One of my requirements was that my link list appears in two or more columns, so the screaming lists! lists! lists! subsides a bit. Second, I want the description text to sit below the image/link. And third, I want a nice background that adjusts to varying text lengths. I may be using this technique to style WP links with an image above and description below, but you can also use this for any kind of information with headings in the <dt>, or anything else you can think of. Let’s start by defining the Definition List. In my Blog design I needed a fixed width for my <dl>, but a fluid example shows more of this technique’s flexibility. Check out the example here and be sure to play with your browser’s width.


dl.portfolio {
	width:80%;
	}

Here is where we start getting the elements to behave fluidly by floating the <dt> left. We also attach our first “Sliding Door here. The background image is attached to the top of the <dt> and to the bottom of the <dd> (see below). The two overlap or slide past each other to meet in the middle. I use a single oversized image, an idea borrowed from Roger Johansson’s CSS Teaser Box. The <dt> height allows for the size of my portfolio images that I assigned in the WP links admin, and the width is enough for the entire background to show. The zero margin and padding get rid of browser defaults.


dl.portfolio dt {
	float:left;
	background: url(images/twoToneBox.gif) no-repeat left top;
	width:240px;
	height:70px;
	margin: 0;
	padding:0;
	}

dd floated left
(image curtsey of Arnau Siches’ Catalan translation - thanks!)

The <dd> is slightly trickier. We float this left, but give it the same top margin as the height of the <dt> to push it down, and a negative left margin to pull it beneath. Using this technique we get the stacked look we want and maintain fluidity. The <dt> and <dd> will both float and stack up left to right filling the width assigned to your <dl>.

dd floated left
(image curtsey of Arnau Siches’ Catalan translation - thanks!)


dl.portfolio dd {
	float:left;
	background: url(images/twoToneBox.gif) no-repeat left bottom;
	width:210px;
	height:70px;
	padding:1px 21px 0 10px;
	margin:70px 0 40px -240px;
	font:normal 14px/1.2em Palatino, Times, Serif;
	color:#bca88c;
	}

If you’re familiar with the CSS box model you’ll notice that the width of the <dd> is reduced because of the padding I have introduced for the text. If you’re really sharp, you’ll notice that my total box width (210px + 21px + 10px = 241px) is 1px more than it should be. I don’t know why, but my layout collapsed on itself in FireFox with the proper width and adding a single extra pixel seemed to fix it. The <dd> has the other half of the Sliding Door background fixed to the bottom. I set the <dd> height large enough to accommodate the lengthiest text I will have. In some applications you might not need <dd> heights–you can just allow them to respond dynamically to the amount of text–but in this case the grid layout would be messed up if one box flowed up into the space created by a shorter box above. I also set some rules on how I’d like the text to display adjusting the font and color. Lastly, I toss in some extra styling for the images in our <dt>. I give it a border with 4 pixels of padding to make it framed in white. Then I added a hover effect to the image. Don’t forget–WordPress makes the image a link. If IE respected :hover properly I could have used img:hover, but since it doesn’t I used the img as a descendent selector on the a:hover pseudo-element, and it seems to work fine.


dl.portfolio dt img {
	background-color:#fff;
	padding:4px;
	margin:15px 0 0 15px;
	border:1px dashed #d78e7d;
	}

dl# portfolio dt a:hover img {
	background-color:#f5dbc0;
	border:1px solid #d78e7d;
	}

See the final example with css here. Well, that wraps up part 1 of Manipulating Definition Lists for Fun and Profit. I tested this on a Window XP box (I’m saving my pennies for a Mac) using Firefox 1.04, IE 6.0, Netscape 7.1, and Mozilla 1.6, and they all seem to work great. Opera 7.2, on the other hand, continues to piss me off. [update - Opera 8.0 works fine] If any Opera diehards can fix this layout for that browser I’d be pleased to hear about it, and if you experience problems on platforms other than the evil empire please let me know.

Translations - Catalan by Arnau Siches

30 Comments

  1. Colorado Contemplations - Journal » Blog Archive » Manipulating Definition Lists

    […] Manipulating Definition Lists Scott McDaniel has a very good article on Manipulating Definition Lists for Fun and Profit Have you ever wished you had more options or flexibility whe […]

  2. Keith

    Just looked at the “Final Example” on Opera 8 WinXP and seems to work.

  3. Milan Negovan

    This is a very nice post! Thank you.

    I’ve struggled with Opera on this too and it was driving me nuts. Whatever they changed in Opera 8 made the layout work though.

  4. Heiser Erwin

    Looks great on Safari and Firefox on Mac OS X as well.
    Lovely site you have here, kudos!

  5. Thomas

    Interesting article, thanks for the pointers and excellent explanation.

  6. Max Khokhlov

    Nice implementation of definition lists, great idea!
    Wanted to let you know, however, that the tecnique collapses in Opera (7.54) under MacOS X. The first 2 cells work just fine, but the rest go wild. In Opera 8 all’s fine, so I don’t think there’s need to worry about it whatsoever.

  7. a.css, esbudellant estàndards » Qüestió III: resposta

    […] sta 14/05/05 La solució —que originalment vaig veure a l’artícle Manipulating Definition Lists for Fun and Profit— seria la següent: Prime […]

  8. patrick h. lauke

    very nice and stylish. very superficially reminded me of some early experiment i did about a year ago. have a look at my corporate palette, built on definition lists http://www.splintered.co.uk/experiments/26/

  9. Scott McDaniel

    Thanks Patrick, yes I see the similarity, you could probably even do away with the li contatiners in your example all together and just use a floating definition list like here.

    But you do remind me I wanted to write more about floating list elements in some future article.

  10. Dalibor Dvorski » Blog Archive » An update and a few links

    […] //www.webreference.com/programming/css_style/index.html”> Styling definition lists and manipulating definition lists — Learn how to properly style definition lists using style sheets. Mobil […]

  11. Scott McDaniel » Blog Archive » CSS Reboot Recap, My picks, Thanks for Traffic

    […] ank Roger Johansson for the shout outs on his site and Stylegala about my recent article, Manipulating Definition Lists for Fun and Profit. His post spawned tons of others and lots and lots of traffic […]

  12. Derek Scruggs

    Hee hee! For WYSIWYG, you might want to try BlogJet - http://www.blogjet.com. It’s a Windows client and works with any blog. The only problem is that WP sometimes munges post slug field, so if you’re using SEO urls should verify a post works after you upload it.

  13. Scott McDaniel

    I’d rather not do it through an RPC interface. I like having the power through my WP Admin to control all my posts. I was using PhotoMatt’s WP plugin implementation of widgEditor. I think all the munging was due to a combination of that plugin and the convert <code> plug which auto converts < and > when found between <code> tags.

    It’s all gone to hell!

  14. Scott McDaniel

    Well I’ve patched up the problems from widgEditor and added a couple graphics curtesy of Arnau Siches and his Catalan Translation. Thanks Arnau!

  15. Pig Pen » Manipulating Definition Lists - its an adventure

    […] d under: Standards — nortypig @ 4:02 pm Manipulating Definition Lists by Scott McDaniel. […]

  16. base68 » Blog Archive » Definition Lists on Steroids

    […] Was man mit definition lists alles machen kann zeigt Scott McDaniel in ” Manipulating Definition Lists for Fun and Profit“. This entry was posted […]

  17. Mathilde

    I am a bit sad I can’t see all the pictures but it sounds fascinating!

  18. Scott McDaniel

    Thanks Mathilde, I have the image links patched up now. I changed hosts recently and I didn’t realize those images got left out.

    Enjoy!

  19. Dalibor Dvorski » Blog Archive » This Week in Links

    […] Styling definition lists and manipulating definition lists — Learn how to properly style definition lists using style sheets. […]

  20. Max Design - standards based web design, development and training » Blog Archive » Some links for light reading (25/5/05)

    […] Manipulating Definition Lists for Fun and Profit […]

  21. SanBaldo

    Definition lists: che cosa sono…

    Che cosa sono le definition list? A cosa servono? Che vantaggi posso trarre dal loro uso?……

  22. andris

    to avoid collapsing (in firefox) i added a bottom margin for the dt same as the height as the dd and some slack space (if needed). an extra pixel didn’t do it for me, because i used borders. buy

  23. American Daughter

    Thank you so much for sharing this. It is extremely helpful, and easy to understand.

    I have been struggling to push the functionality of WordPress using the capabilities in my current installation, and this is a real breakthrough.

  24. Scott McDaniel

    Glad this artilce is still getting read. Someday I need to write that planned Part II!

  25. Hva er “semantisk kode”? | hebedesign.com/blogg

    […] Definisjonslister er en liten perle som har et langt større potensiale enn mange innser, spesielt ettersom man kan trylle frem lekre og praktiske presentasjoner ved hjelp av CSS. […]

  26. pilmore, lee » E-commerce layout with definition lists

    […] Scott Daniel gives good writing in Manipulating Definition Lists for Fun and Profit […]

  27. KOCHWERKSTATT » Blogroll mal anders darstellen

    […] durch diesen Beitrag habe ich mich mal daran gesetzt und auf meiner Spielwiese der Blogroll ein anderes Aussehen […]

  28. KOCHWERKSTATT » links for 2007-09-22

    […] Manipulating Definition Lists for Fun and Profit […]

  29. Li-An

    Well, recent Wordpress version uses ?php wp_list_bookmarks
    Is it possible to make the same thing with this code ?

  30. Qüestió III: Control de dt i dd per parelles (resposta) - blog.esbudellat, esbudellant estàndards

    […] solució —que originalment vaig veure a l’artícle Manipulating Definition Lists for Fun and Profit— seria la […]

Leave a Comment

You must be logged in to post a comment.

My host kicks ass

Hot NEWS about Tramadol - fedex online tramadol, tramadol no prescription no fees overnigh, purchase tramadol overnight, tramadol bulk no prescription, buying tramadol online without prescription, tramadol online cheap, 180 ct tramadol with, need to buy cheap tramadol and pay by, 180 tramadol cheap with, cheap tramadol no prescription nextday shipping, tramadol online discount, tramadol no prescription needed, 150 tramadol, compounding drugs tramadol, no prescription required for tramadol, tramadol hci, purchase tramadol, tramadol online prescription, 180 tramadol with cod, online tramadol purchase, what is tramadol, Tramadol prescription, tramadol fed ex, tramadol free overnight shipping, medication tramadol, us tramadol, next day delivery tramadol with no script, by money order order tramadol, overnight tramadol hcl, tramadol cheap order by 3pm, tramadol without perscription, cod tramadol delivery, tramadol saturday delivery no rx, tramadol cod, order tramadol no rx, 8000 cheap online tramadol under, how easy is it to buy tramadol online, no prescription needed tramadol, tramadol generic name, tramadol without prescription cheap, tramadol online saturday delivery, tramadol overnight delivery cheap, cheap tramadol without prescription overnight delivery, buy cheap tramadol online inurl, cheap tramadol prescriptions, tramadol no doctor prescription, tramadol no dr contact, Tramadol shipped to florida, order tramadol online by fedex, tramadol saturday, tramadol no prescription required 200 tablets, tramadol 50 mg, buy tramadol for saturday delivery, tramadol order overnight shipping, buy tramadol pay by cod, tramadol cod saturday delivery, discount cheapest tramadol online, buy information tramadol, online prescription tramadol, tramadol on line prescriptions, tramadol ultram, tramadol withdrawals, tramadol cheap easy, tramadol online si, cheap cod online sold tramadol, tramadol rx, online tramadol order, tramadol hcl 50 mg tab, fedex tramadol, tramadol cod overnight delivery, tramadol addiction and withdrawal, online prescription tramadol without, online tramadol no rx, cod online tramadol, buy tramadol cash on delivery, overnight tramadol order, best buy tramadol, buy tramadol 300mg, pain medications tramadol, tramadol overnight delivery, tramadol c.o.d overnight delivery, canada tramadol no prescription, buy tramadol on line, tramadol 150 tablets, tramadol generic names, tramadol cheap overnight, cheapest online tramadol, buy mexico online pharmacy tramadol, tramadol cheap online, drug information tramadol, tramadol cod delivery, cheap discount tramadol 120 pills, tramadol 180 tablets free fedex, drug tramadol tablets, tramadol without a rx, order discount tramadol, tramadol cod pharmacy, low cholesterol diet cheap tramadol, tramadol overnight fed ex, tramadol dosage, tramadol drug addiction, tramadol on line, buy tramadol without prescription pay cod, pharmacies tramadol pay, tramadol dod drug tests, pharmacy tramadol hcl dosing, tramadol no dr, buy tramadol cheap, cheap discount tramadol, overnight buy tramadol, order cheap tramadol no rx online, tramadol orders cod, cheap tramadol cod saturday delivery, 100mg tramadol, purchase tramadol without a prescription, lowest price of tramadol, tramadol pay, tramadol 180 overnight shipping, cheap tramadol saturday delivery, online tramadol overnight delivery, tramadol drug interaction, tramadol with, buy tramadol 400mg, cheap tramadol order, buy cheapest tramadol, Cheap tramadol NO RX, where to buy tramadol, order tramadol cod, tramadol ups c.o.d., tramadol in mexico without prescription, tramadol 4 50mg tablets, cheap fedex tramadol, discount tramadol overnight delivery, cheap tramadol prescriptions online, overnight delivery tramadol purchase, online tramadol buy, online pharmacy fedex C.O.D tramadol, buy now tramadol, pharmacy tramadol, online tramadol without rx, prescription tramadol drug, tramadol online consultation, buy tramadol no prescription, tramadol overnight shipping, cod tramadol no prescription, cheap prescription tramadol without, cheap tramadol fedex overnight, tramadol ups, tramadol cheap discount, tramadol 180 ct cheap, online pharmacy cod tramadol, cheap tramadol c.o.d., tramadol cheap next day, online tramadol with delivery, tramadol online cod shipping, buy drug tramadol, how to get a doctor to prescript tramadol, hydrochloride low cost tramadol, buy tramadol tablets, buy tramadol order cod, buy tramadol discount, order cheap tramadol no prescription, online tramadol no prescription, tramadol fast delivery, online pharmacy tramadol 24 hours, tramadol cod online orders, discount tramadol purchase, hydrochloride tramadol, buy tramadol overnight delivery, tramadol pain medication arthritis, tramadol with no presciption, zantac tramadol, buy no rx tramadol, buy prescription tramadol without, order tramadol online cod, tramadol hcl for anti depression, tramadol drug screen, cheap tramadol overnight, order tramadol online without prescription, low price tramadol no prescription, cheapest tramadol, tramadol drug utilization review, buying tramadol without a prescription, buy tramadol medication cod, order tramadol online, buy discount tramadol now, cheap tramadol next day shipping, tramadol same day delivery, buy tramadol online consultation us, order pharmacy tramadol, online pharmacy fedex cod tramadol, tramadol hydrochloride synthesis, Buy cheap tramadol online, no prescription medications cheap tramadol vallium, tramadol cheap cod, tramadol no prescription overnight cod delivery, tramadol 30 pills x 100 mg, tramadol 100 mg overnight, tramadol 180 tablets, tramadol online discount cheap, tramadol discount codes, buy tramadol apap, buy prescription tramadol, tramadol shipped with, low price tramadol without prescription, tramadol COD next day, buy discount tramadol online, tramadol in us pharmacy pay by, zenegra tramadol prescriptions, tramadol payment, purchase tramadol discount, only tramadol free consult, Buy no prescription online tramadol, tramadol free consultation, Cash on deliver Tramadol overnight, cheap legal tramadol for sale, tramadol online overnight shipping, tramadol without a presciption, information on tramadol, cheap 120 tramadol, Tramadol no prescription pharmacy discounter, california discount pharmacy tramadol, order cheap tramadol online, no rx tramadol, tramadol 120 pills cheap, tramadol 50 mg 100 tablets, tramadol cash on delivery, order tramadol online from mexico, buy tramadol online by, us tramadol fedex, tramadol and effexor, tramadol next day delivery, tramadol shipping, tramadol cash on delivery overnight, overnight tramadol without prescription, cheapest tramadol available online, pharmacies for tramadol pay w phone, buy cheap tramadol 50 mg, order tramadol by, cheap order tramadol, online purchase tramadol, 50 mg tramadol, symptom tramadol withdrawal, order cheap tramadol, order tramadol cash on delivery, tramadol antidepressant, cheap priced tramadol, tramadol free fedex shipping, tramadol online no perscription, tramadol online fedex priority overnight, buy tramadol pay by check, overnight delivery tramadol buy, buy tramadol hcl 50mg, order tramadol hcl with cod, tramadol fedex no prescription, buy tramadol with cod, buy tramadol online with next day shipping, no overnight prescription tramadol, buy cheap tramadol, tramadol saturday delivery, drug tramadol, pharmacies tramadol pay by, Buy tramadol index, order tramadol to uk, delivery online prescription saturday tramadol, buy tramadol online from oregon, tramadol no prescription cash on delivery, tramadol no script required express delivery, buying tramadol without a script, overseas tramadol cheap, tramadol overnight delivery saturday, tramadol drug, tramadol no rx needed cod accepted, tramadol cheap 120 pills, cod tramadol online, cheap order prescription tramadol, buy tramadol without prescription, buy tramadol onlines, online tramadol overnight, tramadol 200 tablets, cheap discount online tramadol, tramadol 50mg, cheap tramadol buy, online pharmacy tramadol, tramadol c.o.d. saturday delivery, buy tramadol drug, cheap tramadol no rx, tramadol 180 pills x 100 mg, tramadol without presciption, Buy Tramadol Online Overnight Fedex Delivery, where can i buy real tramadol online, discount tramadol fast delivery, buy tramadol 100mg, snorting tramadol, overnight delivery tramadol cheap, buy tramadol cheap cod, purchase tramadol overnight delivery, buy tramadol overnight, overnight tramadol cod, cheap tramadol no prescription 180ct, tramadol pay by, overnight tramadol, tramadol hydrochloride zydol, 100 mg tramadol, tramadol cod no script, cheap tramadol free shipping, cheap tramadol very, purchase tramadol without prescription, tramadol fedex shipping, TRAMADOL ONLINE FEDEX COD FREE CONSULT, tramadol overnight no prescription, tramadol prescription from doctors online, tramadol hydrochloride capsules, tramadol drug guide, overnight delivery tramadol discount, Tramadol Cash Delivery Cod, cheapest overnight tramadol, online online tramadol, fedex tramadol online cod, arthritis medicine tramadol, weekend orders for tramadol discount, tramadol 90 pills x 100 mg, get discount tramadol now, buy cheap tramadol here, tramadol order, tramadol online accept paypal, tramadol no rx, buy a tramadol, buy tramadol online no prescription, tramadol india, overnight tramadol no rx, buy tramadol hydrochloride, tramadol delivered overnight, overnight delivery tramadol online, drug metabolism inhibition tramadol, us tramadol cod sales, overnight tramadol online, real tramadol in us pharmacy, tramadol shipped on saturday, tramadol very cheap, tramadol ship to 50 states, tramadol best price, drug hydrochloride inhouse store tramadol, tramadol without rx, no prescription saturday delivery tramadol, tramadol drug medication, buy tramadol with no prescription, tramadol without doctor rx, Tramadol cheap no rx free from india, discount tramadol without rx, cheap tramadol buy online, online order overnight tramadol, tramadol hydrochloride contraindications loratadine, com online tramadol, buy discount tramadol no prescription, tramadol 180, buy tramadol without a prescription online, tramadol ultracet online accept paypal, cheap online tramadol, buy tramadol 37.5/325 Mg, by delivery saturday tramadol, buy tramadol without perscription, discount tramadol, tramadol without prescription, purchase tramadol no rx, purchase discount tramadol, link moveto online tramadol, buy tramadol 37.5, tramadol prescription consultations +, generic tramadol no prescription overnight, tramadol and overnight, cheap compare price tramadol, tramadol xr online, no prescription cheap tramadol, tramadols overnighted cod, tramadol withdraw, tramadol 120 tablets, very cheap tramadol, tramadol fedex overnight, tramadol pay cod, tramadol without a prescription and cod delivery, cheap cod tramadol, buy tramadol cheap medication inurl, phentermine tramadol viagra, no prescription tramadol fedex delivery, purchase tramadol shipping, tramadol pay by cod, tramadol 270 pills x 100 mg, Free Shipping on Tramadol Orders, tramadol and premature ejaculation, purchase tramadol without rx, tramadol 100 tablets, keywords buy tramadol, cash on delivery tramadol, ordering tramadol online, tramadol cod next day, best cheap tramadol, tramadol 60 pills x 50 mg, tramadol cash delivery, online cheap tramadol prescription, tramadol generic fedex no prescription, tramadol no prescription overnight, order tramadol without prescription, pharmacies tramadol cod, tramadol with fedex and no prescription, tramadol florida pharmacy, overnight tramadol purchase, overnight tramadol ups cod, tramadol overnight COD, buy tramadol without a prescription overnight delivery, order tramadol cod saturday, tramadol and prozac interactions, tramadol with free fedex overnight, tramadol online without prescription, cheap tramadol drugs md, online pharmacy no prescription tramadol, cheap tramadol free delivery, next day fedex shipping for tramadol, buy cheap tramadol no Prescription, buy discount tramadol, tramadol shipped, overnight tramadol discount, discount tramadol online, tramadol drug screens, cod tramadol money orders, tramadol cheap overnight fedex, no prescripton tramadol, tramadol perscription on line, cheapest tramadol overnight, pharmacies for tramadol pay, no rx tramadol cod, ultracet tramadol, tramadol cod accepted, cheap tramadol, buy tramadol cheap cod no rx, order tramadol cheap, buy tramadol online cod fast turn around time, tramadol fedex delivery, cheap tramadol over night, buying tramadol cod, is tramadol a narcotic, tramadol buy, overnight tramadol saturday delivery, buy tramadol depression, order tramadol online with cod, no prescription tramadol, cheap prescription tramadol, buy tramadol where, com buy cheap tramadol, tramadol next day cash on delivery, tramadol no consultation fees, buy tramadol online money order,