View Full Version : Attempting to style Definition Lists ( <dl>'s )
Ok, in my continuing quest to try and apply — what I thought would be — a simple style to an online resume (as per my other thread (http://www.codingforums.com/showthread.php?t=89384)), I've been exploring the possibility of trying to use a styled <dl> to achieve my needs.
If you recall I'm trying to craft CSS to achieve a
[right-aligned label] [space] [paragraph content]
but without the use of tables. If I have to use nested <divs> then so be it. But a fellow forum member suggested trying a definition list for the task, which prima facie seemed idealy suitable.
Visually what I'm after could be described as:
{gap}
+----------------+ +-----------------------------------------------+
| <dt> | | <dl> {content..} |
+----------------+ | { may span more than one line but would still |
| like it to be aligned with the <dt> } |
+-----------------------------------------------+
But after an afternoon's fiddling, I've pretty well gotten nowhere :(
Using the following test page: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html401/strict.dtd">
<html>
<!--// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //-->
<head>
<meta http-equiv="Content-Language" content="en-AU">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>resume</title>
<style type="text/css">
dl { /* Definition List */
width: 100%;
padding-top: 1px;
margin-top: 1px;
margin-bottom: 1px;
display: block;
}
dt { /* Definition List: Term */
width: 30%;
display: inline;
float: left;
height: 100%;
}
dd { /* Definition List: Definition */
width: 50%;
display: block;
height: 100%;
float: left;
}
div.listwrap {
border: 2px gray solid;
}
.listdebug {
border: 1px red solid;
}
.listdebug dt {
border: 1px blue solid;
}
.listdebug dd {
border: 1px green solid;
}
</style>
</head>
<!--// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //-->
<body>
<div class="listwrap">
<dl class="listdebug">
<dt>Name: </dt>
<dd>Some Guy</dd>
<dd>a.k.a Mr. Normal</dd>
</dl>
</div>
</body>
<!--// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //-->
</html>
I can't seem to get the second <dd> element to line up with the <dt> margin no matter what I've seemed to try. So after having tried random shots in the dark, I'm once again appealing for assistance <sigh>
I've also wrapped my list in some borders to just see what was going on, and I must say I can't really work it out. The list is supposed to be wrapped in a box (just for testing). But it doesn't seem to be. :confused:
Can anyone point me in the right direction here? or should I give up on the <dl> idea??
Ok, thanks to the examples this page (http://www.washington.edu/webinfo/snippets/css/lists.html), I think I might have got it.
I'm just trying it out now.
(Shows how little I understand what I'm doing in CSS though)
ronaldb66
06-21-2006, 11:56 AM
Just some remarks:
A dt element is inline by default; you don't need to give it an display: inline. In fact, floating it in fact implicitly turns it into block mode.
In the example you've given, and as you tried yourself, floating the dt's left is the way to get them to align next to the dd blocks. The key is to also clear them left to prevent them from floating up underneath eachother.
Also, in the example the dd's are given a left margin to create a space for the dt's to sit in. This margin determines how wide the dt's can get (any wider and things turn ugly). Alternatively, you could add an explicit width to the dt's (smaller than the left margin) so longer texts wrap around to the next line, keeping things nice and tight.
ronaldb66
06-21-2006, 12:30 PM
A dt element is inline by default That statement may be wrong; I can't seem to find it in the DTD. Nonetheless, it still doesn't require to be inline.
I tried out some things and the seem to work fine; limiting the width of the dt's nicely wraps texts longer then the width onto the next line, preserving the columnar layout.
Creating a left column for the dt's can be achieved either by margin-left or padding-left on the dd's; what works best for you depends in part on whether you want to use background properties.
Arbitrator
06-21-2006, 08:46 PM
The definition list elements are displayed as block by default. Default (Firefox):
dl {margin: 1em 0;}
dl, dt, dd {display: block;}
dd {margin-left: 40px;}
Based on some experimentation (http://jsg.byethost4.com/demos/dl.xhtml) (XHTML) I did, it looks like width and floats are the best way to go as opposed to inline. I really think a table would be so much easier in this situation though.
Kravvitz
06-21-2006, 09:27 PM
Creating a left column for the dt's can be achieved either by margin-left or padding-left on the dd's; what works best for you depends in part on whether you want to use background properties.
Using padding-left might not work in IE if the <dt> "hasLaytout", which triggers some of IE's incorrect float behavior.
ronaldb66
06-22-2006, 07:26 AM
For lack of a better browser, I tried it out in IE6 and didn't see any immediate problems; I haven't tested it to bits, though, so you may very well be right.
ok. Thank you very much everyone for your help so far.
I seem to have it mostly working at the moment :) whoo-hoo! :cool: :thumbsup:
The CSS looks a little kludgy to me though. But, I'm just very glad to have it doing what it's supposed to do.
However... :p
I now only have one problem left that I haven't been able to sort out all day yet. It involves styling nested DL lists.
As mentioned; it's a resume. I've had a couple of jobs which involve different roles within the same company. Instead of just listing them, I aslo wanted to show the length of time that was spent in each role on the RHS.
A second DL list nested under the appropriate <dd> seemed the way to go since I knew of no other way of relyably getting a span or a div to move just one element on the same line to the far right. (I'm somewhat inexperienced though, so I just mightn't know...). It also seems more semantically correct, fitting in with how the rest of the data in the page is coded.
So I need to go from this: ┌--<DL>--------------------------------------------------------------------┐
| |
| {gap} |
| ↓ |
| ┌-<dt>---------------┐ ┌-<dd>------------------------------------------┐ |
| | Positions: | | {Job role #1 ... } | |
| └--------------------┘ | {Job role #2 ... } | |
| | {Job role #3 ... } | |
| └-----------------------------------------------┘ |
| |
| ┌-<dt>---------------┐ ┌-<dd>------------------------------------------┐ |
| | Company: | | {company name} | |
| └--------------------┘ └-----------------------------------------------┘ |
| |
| |
| {...} |
└--------------------------------------------------------------------------┘(which is currently working), to this: ┌--<DL>--------------------------------------------------------------------┐
| |
| {gap} |
| ↓ |
| ┌-<dt>---------------┐ ┌-<dd>-------------------------------------------┐|
| | Positions: | |┌-<DL>-----------------------------------------┐||
| └--------------------┘ ||┌-<dt>--------------------------┐ ┌<dt>-----┐|||
| |||{Job role #1 ... } | | {#yrs}||||
| ||└-------------------------------┘ └---------┘|||
| |└----------------------------------------------┘||
| |┌-<DL>-----------------------------------------┐||
| ||┌-<dt>--------------------------┐ ┌<dt>-----┐|||
| |||{Job role #2 ... } | | {#yrs}||||
| ||└-------------------------------┘ └---------┘|||
| |└----------------------------------------------┘||
| |┌-<DL>-----------------------------------------┐||
| ||┌-<dt>--------------------------┐ ┌<dt>-----┐|||
| |||{Job role #3 ... } | | {#yrs}||||
| ||└-------------------------------┘ └---------┘|||
| |└----------------------------------------------┘||
| └------------------------------------------------┘|
| ↑ |
| | |
| {all content on second-level items/lists should |
| start flush left with the previous border} |
| |
| |
| ┌-<dt>---------------┐ ┌-<dd>------------------------------------------┐ |
| | Company: | | {company name} | |
| └--------------------┘ └-----------------------------------------------┘ |
| |
| |
| {...} |
└--------------------------------------------------------------------------┘
...which I've so far not yet been able to style to work :(
I've cobbled up a test page.
It shows one paragraph of the original (working) version style to give you an idea of what it should look like, and a second one with the double-nested <DL> that I'm currently trying to get to behave.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html401/loose.dtd">
<html>
<!--// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //-->
<head>
<meta http-equiv="Content-Language" content="en-AU">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>resume</title>
<style type="text/css">
/* Box model border wrapping debugging styles */
div.listwrap {
border: 2px gray solid;
}
.employment {
border: 1px red solid;
}
.employment dt {
border: 1px blue solid;
}
.employment dd {
border: 1px green solid;
}
/* (Comment out the above to remove boxes drawn around elements for debugging purposes) */
.timeperiod {
background-color: #E2E2E2;
margin-bottom: 20px;
padding: 3px 4px 4px 12px;
font-family: "Arial Unicode MS", sans-serif;
font-weight: bold;
color: White;
width: 100%;
margin-top: 20px;
display: block;
}
/* Defonition List styles */
/* All Definition Lists style */
dl {
padding: 0;
margin: 0;
/* Normal rule styles
- temp. commented out for debugging
margin-top: 3px;
margin-bottom: 3px;
*/
}
dl:hover {
background-color: #FFFDFB;
}
/* Definition List: all [Definition Term] styles */
dt {
float: left;
clear: left;
/* margin-right: 0.3em; */
line-height: 120%;
text-align: right;
font: 0.9em "Arial Narrow", sans-serif;
font-weight: normal;
color: #333334;
}
/* Definition List: [Definition] style */
dd {
text-align: left;
font: 0.9em "Palatino Linotype", serif;
font-weight: normal;
}
/* set DL text height on MastHead to compensate for larger DD font size */
dl.employment dd.mastitem
{
line-height: 155%;
}
/* set employment section widths (one other section is a different set of widths) */
dl.employment dt {
width: 25%;
}
dl.employment dd {
margin-left: 27%;
}
/* set MastHead font styles (to display JobTitle and Company Name in a larger font size)*/
dl.employment dd.position {
font-family: "Arial Unicode MS", Arial, sans-serif;
font-size: medium;
font-weight: bold;
}
dl.employment dd.org {
font-family: "Arial Unicode MS", Arial, sans-serif;
font-size: medium;
font-weight: normal;
padding-bottom: 8px;
border-bottom: 1px solid #DCDCDC;
height: auto;
}
/* set nested DL.dt styles for multiple job positions held within one company */
dl.employment dd dl dt.jobtitle {
clear: left;
padding: 0px;
margin: 0px;
width: auto;
float: left;
font-family: "Arial Unicode MS", Arial, sans-serif;
font-size: medium;
font-weight: bold;
text-align: left;
}
/* set nested DL.dd styles for right-aligning the length of time that each position was held */
dl.employment dd dl dd.period {
clear: left;
padding: 0px;
margin: 0px;
float: right;
width: 5em;
text-align: right;
font-weight: normal;
}
/* Routine Style defiinitions */
H1, H2, .h22 {
font-family: Arial, sans-serif;
font-weight: bold;
text-align: left;
}
H1 {
border-top: 1px solid Maroon;
background-color: #FFFAFA;
font-size: large;
page-break-before: always;
}
H2 {
margin-bottom: -0.3em;
}
.smaller {
font-size: smaller ! important;
}
</style>
</head>
<!--// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //-->
<body>
<h1>Employment History</h1>
<p>Original Working example: (sans right-aligned time periods)</p>
<!-- Widgets-R-Us : Original (working) example -->
<div class="timeperiod">October 1994 ➔ February 2000</div>
<div><!-- Position and Organisation -->
<dl class="employment">
<dt class="mastitem">Position: </dt>
<dd class="position">Director — Marketing</dd>
<dd class="position smaller">Chief Widget Designer — Research And Development</dd>
<dd class="position smaller">Janitor — Workshop Factory Floor</dd>
</dl>
</div>
<br>
<div><!-- Position and Organisation -->
<dl class="employment">
<dt class="mastitem">Company: </dt>
<dd class="org">Widgets-R-Us (Head Office)</dd>
</dl>
</div>
<br>
<div><!-- Details -->
<dl class="employment"><!-- Reporting to -->
<dt>Reporting to: </dt>
<dd>The Tea Lady (daily)</dd>
</dl>
<br>
<dl class="employment"><!-- Company Profile -->
<dt>Company Profile: </dt>
<dd>Sample text to see how paragraphs might wrap to the next line. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus vitae ligula nec elit euismod rutrum. Duis non eros ac nisi lacinia vehicula. And so on, ad nauseum ad infinitem.</dd>
</dl>
<br>
<dl class="employment"><!-- Primary Responsibilities -->
<dt>Primary Responsibility: </dt>
<dd>New Widget Development and long-term strategic Product Planning for International Dumping - err.. I mean 'Markets'.</dd>
<dd>[Position Description available]</dd>
</dl>
</div>
<p>Cool! <br>
So far so good. But would like to add one further piece of information. So...</p>
<p>This next example is largely the same code, but attempting to also show the
length of time that each job was held within a company too, right-aligned. </p>
<p>This uses a second <DL> nested
within the original <DL> ➙ <DT><DD> </p>
<!-- Widgets-R-Us : 'enhanced' example -->
<div class="timeperiod">October 1994 ➔ February 2000</div>
<div><!-- Position and Organisation : Test styles -->
<dl class="employment">
<dt class="mastitem" style="list-style-type: none;">Position: </dt>
<dd>1st level, pre-2nd level test dd</dd>
<dd>
<dl>
<dt class="jobtitle">Director — Marketing</dt>
<dd class="period">(1¾ years)</dd>
</dl>
<dl>
<dt class="jobtitle smaller">Chief Widget Designer — Research And Development</dt>
<dd class="period smaller">(1¾ years)</dd>
</dl>
<dl>
<dt class="jobtitle smaller">Janitor — Workshop Factory Floor</dt>
<dd class="period smaller">(1¾ years)</dd>
</dl>
</dd>
<dd>1st level, post-2nd level test dd</dd>
</dl>
<br>
<dl class="employment">
<dt class="mastitem">Company: </dt>
<dd class="org">Widgets-R-Us (Head Office)</dd>
</dl>
</div>
<br>
<div><!-- Details -->
<dl class="employment"><!-- Reporting to -->
<dt>Reporting to: </dt>
<dd>The Tea Lady (daily)</dd>
</dl>
<br>
<dl class="employment"><!-- Company Profile -->
<dt>Company Profile: </dt>
<dd>Sample text to see how paragraphs might wrap to the next line. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus vitae ligula nec elit euismod rutrum. Duis non eros ac nisi lacinia vehicula. And so on, ad nauseum ad infinitem.</dd>
</dl>
<br>
<dl class="employment"><!-- Primary Responsibilities -->
<dt>Primary Responsibility: </dt>
<dd>New Widget Development and long-term strategic Product Planning for International Dumping - err.. I mean 'Markets'.</dd>
<dd>[Position Description available]</dd>
</dl>
</div>
</body>
<!--// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //-->
</html>
At the moment when displayed in a browser, it's got content from the next line wrapping under. I've tried adding CSS "clear: ..." into my styles at various places, but so far without helping. Though I'm going to try again given I might have "code blindness" from looking at it all day.
I've also added some visable box margins around the lists via the CSS to try and see better what's going on.
I suspect it's because I just don't understand either the CSS box model, or floats, well-enough. However I'm also worried that it could be a quirk that requires a work-around [eg1 (http://positioniseverything.net/easyclearing.html), eg2 (http://www.quirksmode.org/css/clearing.html)] in which case I'm really going to need an experienced coder's assistance.
If anyone feels they might know what's going on, I'd be keen to hear it!
(There's a bit of code there, so best to [select-all], save it and view it as an HTML page)
Thank you again to anyone that gives it a go.
ok, I made a little bit of headway with the new nested <DL> style overlapping with the next <DL>'s content. (I placed a "clear: both;" as an inline style at the start of the next section).
Now the nested DL list is lining up, and without overlapping content, but still has a one-line top margin(?) that I can't seem to get rid of.
Also the debugging box borders I've placing around the styles to see what's going on, seem to indicate that my nested <DL> list isn't part of the previous <dd> that's encasing it :confused:
I relise it's probably difficult to expect other's to copy and paste my code elsewhere themselves, so I've uploaded the test online temporarily, here (http://members.optusnet.com.au/cyber-delic/Resume/test6.htm).
ok!
Well after two afternoons of wailing and gnashing of teeth, I've stumbled across a fix or a workaround (I think by accident :p )
In my dl.employment dd dl { style (you'll have to see the code for yourself if you're interested), I added: display: table; and width: 100%; to seemly fix it.
I still have no idea why the original problem was occouring, or what the 'proper' remedy might be; but there you have it, a fix that seemingly works in FF and IE. Fingers crossed for other browsers.
Arbitrator
06-25-2006, 12:46 PM
Heh, that's kind of surprising since display: table doesn't work in IE. If it works, it works, I guess though. :p
hmm, ok. I don't disbelieve you at all, but all I can say is; it's doing something different with it in the class.
(Try it for yourself ?)
Actually, I might have to take that back -- I just removed the statement and it's still working -- lol.
That must mean that it was the width statement then. But I'm sure I tried both...:confused:
Oh well, I'm just grateful for it to be working now :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.