View Full Version : Need to connect two columns of text with dots
jrawdon
03-03-2007, 09:41 PM
I'm building a CSS page that has items down the left side connected to items on the right using ellipses like so:
Item 1 (Left Justified)......................This (Right Justified)
Item 2 ........................................ That
Item 3 ................................. The Other
I've planned to use an empty block with a dotted bottom-border for the ellipses, but it does not need to be collapsable, just with an automatically set width determined by the gap between the left and right columns with some margin built in.
It seems like it should be simple, but I'm not finding the solution. Any help is most hugely appreciated.
Thanks in advance.
VIPStephan
03-03-2007, 11:02 PM
Looks like the general layout you are aiming for is best achieved with a table. However, a bottom border would be below the text so we need to use a background image (one dot, repeating horizontally), and the text would be within span elements that have a backgorund color to cover the background image.
Well, hard to explain so here's an example: http://www.primacom.net/~k6531190/table.htm
However, the table has to have a specific width which is determined by the space of the dots because if not there might be an inconsistency in the dotted line where the left and right cells meet.
Excavator
03-03-2007, 11:33 PM
Hello jrawdon,
This works ok but I don't like how the <hr /> acts in different browsers. Would be best if you made your own dot.gif to repeat as a background, like VIPStephan suggests. Not sure I agree with the tables suggestion though...
Have a look:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
html, body{
text-align: center;
background-color: #33CCCC;
}
* {
margin: 0;
padding: 0;
}
#container {
width: 780px;
margin: 100px auto 0 auto;
background-color: #999999;
overflow: hidden;
}
.left {
height: 24px;
float: left;
clear: left;
padding: 0 5px 0 5px;
text-align: left;
}
.right {
height: 24px;
float: right;
clear: right;
padding: 0 5px 0 5px;
text-align: right;
}
.dots {
height: 24px;
}
hr {
height: 18px;
color: #999999;
background: #999999;
border-bottom-width: 2px;
border-bottom-style: dotted;
border-bottom-color: #000000;
border-top-width: 0px;
border-right-width: 0px;
border-left-width: 0px;
border-top-style: none;
border-right-style: none;
border-left-style: none;
border-top-color: #999999;
border-right-color: #999999;
border-left-color: #999999;
}
p {
font-family: "Comic Sans MS";
font-size: 18px;
}
</style>
</head>
<body>
<div id="container">
<div class="left"><p>Item 1</p></div>
<div class="right"><p>This</p></div>
<div class="dots"><hr /></div>
<div class="left"><p>Item 2</p></div>
<div class="right"><p>That</p></div>
<div class="dots"><hr /></div>
<div class="left"><p>Item 3</p></div>
<div class="right"><p>The other</p></div>
<div class="dots"><hr /></div>
<div class="left"><p>Item 1</p></div>
<div class="right"><p>This</p></div>
<div class="dots"><hr /></div>
<div class="left"><p>Item 2</p></div>
<div class="right"><p>That</p></div>
<div class="dots"><hr /></div>
<div class="left"><p>Item 3</p></div>
<div class="right"><p>The other</p></div>
<div class="dots"><hr /></div>
<!--closes container--></div>
</body>
</html>
VIPStephan
03-04-2007, 01:09 AM
Whether you use a table or not depends on what purpose this "list/table" serves. What will the content represent? That's what you have to think about when you think about the correct HTML to use.
By the looks of the given example I just assumed a table would be appropriate. Prove me wrong.
Arbitrator
03-04-2007, 07:38 AM
Not sure I agree with the tables suggestion though...Assuming that the data is related, a table is fine for this. On the other hand, I wouldn’t exactly call your use of paragraph elements semantic.
Here’s an example (http://jsg.byethost4.com/demos/CF%20108909.html) that looks more like what the OP requested. The main drawbacks are (A) that it relies on font size for perfect alignment and (B) that it fails to work correctly when the text on either side is more than one line in height. For the latter reason, I used white-space: pre to prevent line-breaks.
The technique works in the latest versions of Firefox, Internet Explorer, and Opera; it’s one pixel above the desired location in Opera, but I’d say that that’s an okay trade-off. It should work in Internet Explorer 6 as well; you just need to assign classes to all of the cells in the last column and to the second row in the header since that browser doesn’t support the CSS sibling combinator (+). That’s more verbose and I didn’t feel like typing it.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CF 108909</title>
<meta name="Author" content="Patrick Garies">
<style type="text/css">
* { margin: 0; padding: 0; }
html { padding: 1em; font: 16px/1.2em "Lucida Sans Unicode", "Lucida Grande", sans-serif; }
table { margin: 0 auto; border-collapse: collapse; }
tr > * { padding: 0.1em 0; }
cite { font-style: normal; }
thead tr + tr { display: none; }
tbody tr { background: url("dot.gif") 0 78% repeat-x; }
tbody th, tr td + td { text-align: right; }
tbody th { background: white; padding-right: 0.4em; font-weight: normal; }
tr td + td { padding-left: 0.4em; }
span { padding: 0 0.2em; background: white; white-space: pre; }
</style>
</head>
<body>
<table>
<thead>
<tr>
<th colspan="3"><cite>Dragonseye</cite> Table of Contents</th>
</tr>
<tr>
<th scope="col" abbr="Chapter">Chapter Number</th>
<th scope="col" abbr="Title">Chapter Title</th>
<th scope="col" abbr="Page">Initial Page Number</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"></th>
<td><span>Prologue</span></td>
<td><span>1</span></td>
</tr>
<tr>
<th scope="row">1</th>
<td><span>Early Autumn at Fort’s Gather</span></td>
<td><span>4</span></td>
</tr>
<tr>
<th scope="row">2</th>
<td><span>Gather at Fort</span></td>
<td><span>49</span></td>
</tr>
<tr>
<th scope="row">3</th>
<td><span>Late Fall at Telgar Weyr</span></td>
<td><span>64</span></td>
</tr>
<tr>
<th scope="row">4</th>
<td><span>Telgar Weyr and the College</span></td>
<td><span>87</span></td>
</tr>
<tr>
<th scope="row">5</th>
<td><span>Weyrling Barracks and Bitra Hold</span></td>
<td><span>104</span></td>
</tr>
<tr>
<th scope="row">6</th>
<td><span>Telgar Weyr, Fort Hold</span></td>
<td><span>138</span></td>
</tr>
<tr>
<th scope="row">7</th>
<td><span>Fort Hold</span></td>
<td><span>162</span></td>
</tr>
<tr>
<th scope="row">8</th>
<td><span>Telgar Weyr</span></td>
<td><span>183</span></td>
</tr>
<tr>
<th scope="row">9</th>
<td><span>Fort Hold and Bitran Borders, Early Winter</span></td>
<td><span>197</span></td>
</tr>
<tr>
<th scope="row">10</th>
<td><span>High Reaches, Boll, Ista Weyrs; High Reaches Weyr, Fort, and Telgar Holds</span></td>
<td><span>217</span></td>
</tr>
<tr>
<th scope="row">11</th>
<td><span>The Trials at Telgar and Benden Weyrs</span></td>
<td><span>238</span></td>
</tr>
<tr>
<th scope="row">12</th>
<td><span>High Reaches and Fort Holds</span></td>
<td><span>261</span></td>
</tr>
<tr>
<th scope="row">13</th>
<td><span>Bitra Hold and Telgar Weyr</span></td>
<td><span>278</span></td>
</tr>
<tr>
<th scope="row">14</th>
<td><span>Turn’s End at Fort Hold and Telgar Weyr</span></td>
<td><span>300</span></td>
</tr>
<tr>
<th scope="row">15</th>
<td><span>New Year 258 After Landing; College, Benden Hold, Telgar Weyr</span></td>
<td><span>327</span></td>
</tr>
<tr>
<th scope="row">16</th>
<td><span>Cathay, Telgar Weyr, Bitra Hold, Telgar</span></td>
<td><span>348</span></td>
</tr>
<tr>
<th scope="row">17</th>
<td><span>Threadfall</span></td>
<td><span>379</span></td>
</tr>
</tbody>
</table>
</body>
</html>
coothead
03-04-2007, 09:50 AM
Hi there jrawdon,
here is another possible div solution...
Due to AaronW's comment that using DIVs is not the correct (semantic) approach, I have replaced the DIVs with an UL. ;)
http://mysite.orange.co.uk/azygous/contents.html
...and here is the code...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>contents</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
* {
margin:0;
padding:0;
}
#container {
width:40em;
padding:1.5em 2em 1.5em 0.5em;
border:0.3em double #999;
font-family:serif;
font-size:1em;
color:#666;
background-color:#faf7e1;
margin:2em auto;
}
#container h1 {
font-size:120%;
text-align:center;
}
ul{
list-style-type:none;
}
.line {
height:1.5em;
background-image:url(images/dot.gif);
background-repeat:repeat-x;
background-position:0 0.9em;
clear:both;
}
.left {
float:left;
color:#666;
background-color:#faf7e1;
padding-right:0.3em;
padding-left:1em;
}
.right {
float:right;
color:#666;
background-color:#faf7e1;
padding-left:0.3em;
}
.numbers {
width:1.5em;
text-align:right;
}
</style>
</head>
<body>
<div id="container">
<h1>Contents</h1>
<ul>
<li class="line">
<span class="left numbers"> </span>
<span class="left">Introduction</span>
<span class="right">vii</span>
</li>
<li class="line">
<span class="left numbers">I</span>
<span class="left">That Art Thou</span>
<span class="right">1</span>
</li>
<li class="line">
<span class="left numbers">II</span>
<span class="left">The Nature of the Ground</span>
<span class="right">35</span>
</li>
<li class="line">
<span class="left numbers">III</span>
<span class="left">Personality, Sanctity, Divine Incarnation</span>
<span class="right">21</span>
</li>
<li class="line">
<span class="left numbers">IV</span>
<span class="left">God in the World</span>
<span class="right">56</span>
</li>
<li class="line">
<span class="left numbers">V</span>
<span class="left">Charity</span>
<span class="right">80</span>
</li>
<li class="line">
<span class="left numbers">VI</span>
<span class="left">Mortification, Non-Attachment, Right Livelihood</span>
<span class="right">96</span>
</li>
<li class="line">
<span class="left numbers">VII</span>
<span class="left">Truth</span>
<span class="right">125</span>
</li>
<li class="line">
<span class="left numbers">VIII</span>
<span class="left">Religion and Temperament</span>
<span class="right">146</span>
</li>
<li class="line">
<span class="left numbers">IX</span>
<span class="left">Self-Knowledge</span>
<span class="right">161</span>
</li>
<li class="line">
<span class="left numbers">X</span>
<span class="left">Grace and Free Will</span>
<span class="right">165</span>
</li>
</ul>
</div>
</body>
</html>
coothead
AaronW
03-04-2007, 02:41 PM
I'm pretty sure that if the data on both sides are connected via dots, then what he's got is a list of related items. Thus, using DIVs is not the correct (semantic) approach. A definition list, maybe.
But the dots are something you'd find in old printed indexes, I think. Trying to reproduce them on the digital canvas is likely to be tricky. There are better ways to keep the readers' eyes on the same line using :hover and odd/even row styling. Granted, the dots do look neat. Heh.
coothead
03-04-2007, 05:10 PM
Hi there AaronW,
I have, because of your comment, attempted to make my offering a little more semantic. ;)
As semantics are not my forte, I may, of course, have failed miserably in this attempt. :eek:
coothead
AaronW
03-04-2007, 06:21 PM
Heh. One rule of thumb is that if it doesn't make sense without any CSS applied, it's not the right way to mark it up ;) In your example, each "row" looks like:
IV God in the World 56
But I think "IV" should somehow be connected to "God in the World 56". A table would be best, I think.
<table>
...
<tbody>
<tr>
<th scope="row">IV</th>
<td>God in the World</td>
<td>56</td>
</tr>
</tbody>
</table>
VIPStephan
03-04-2007, 07:44 PM
And if not then an ordered list with roman numerals might make more sense than divs with three spans in 'em.
jrawdon
03-05-2007, 03:48 AM
Thanks much to all that responded! I've decided I couldn't really do what I wanted the way I intended. Some further info I didn't think to add earlier:
1) I wanted to do this using CSS only without the use of tables, though after some thought (and review of some of the above posts) I decided that this really would be an appropriate use of tables.
2) The items on the left and on the right were of varying lengths from line to line and not well-given to fixed-width elements.
3) My background for this list was a gradient, light to dark from left to right, so blocking out borders or images with a single background color showed up as obvious.
I keyed on the comment from AaronW about odd/even row styling and decided that using periods to connect left and right elements was perhaps a bit of a Luddite-like approach.
So, after many hours spent battling this issue I thought would be a no-brainer, I finally completed the page. Here's a sample (http://infinity3design.com/specdemo.htm) to demonstrate what I ended up with.
Again, thanks to all of you. The responses were all great, and I've got some great ideas for next time when I don't use a gradient background.
Thanks!
Jeff
jalarie
03-05-2007, 02:42 PM
I've been looking for, basically, the same thing. So far, I have:
<style type="text/css">
/*<![CDATA[*/
.Column1 {
float: left;
width: 200px;
overflow: hidden;
white-space: nowrap;
}
.Column2 {
float: left;
width: 200px;
overflow: hidden;
white-space: nowrap;
}
/*]]>*/
</style>
<div>
<span class="Column1">
aaaaaaaaaaaaaaa bbbb....................................................
</span>
<span class="Column2">
ccccccccccccccccccccccc---------------------------------------------
</span>
dddddddddd
<br style="clear: both;" />
<span class="Column1">
aaaabb....................................................
</span>
<span class="Column2">
cccccccccccccccccccccccccc---------------------------------------------
</span>
dddddddddd
<br style="clear: both;" />
<span class="Column1">
ab....................................................
</span>
<span class="Column2">
ccccccccccccccccccccccccccc---------------------------------------------
</span>
dddddddddd
</div>
</div>
ahallicks
03-05-2007, 03:01 PM
What does the 'CDATA' bit do in the stylesheet?
jalarie
03-05-2007, 03:50 PM
What does the 'CDATA' bit do in the stylesheet?
That's kind of like the commenting lines for script tags. It needs both the beginning and ending lines:
/*<![CDATA[*/
/*]]>*/
VIPStephan
03-05-2007, 04:33 PM
To elaborate a little further on this: In XML documents CDATA (character data) sections can contain non-XML characters such as JavaScript and/or CSS code and the CDATA comments should be used to denote such a section rather than using the old fashioned HTML comments used to hide scripts from old browsers as this will cause the character data section to be hidden too (in XML - which XHTML counts to). At least that's how I've understood from having a glimpse at it back then.
A search always brings answers to questions. Here's a good one: http://lachy.id.au/log/2005/05/script-comments
Arbitrator
03-05-2007, 05:04 PM
I've been looking for, basically, the same thing. So far, I have:Well, some solutions have already been provided. I looked at your example and it doesn’t appear to work unless the content of the second column is left-aligned. Drawbacks I see are that the code is not as semantic as tables and that you have to put meaningless characters (periods and hyphens) into the source.
What does the 'CDATA' bit do in the stylesheet?The CDATA section markers prevent the less-than sign and ampersand characters from being parsed as the beginnings of tags and character references in an XHTML document. They’re commented out for the benefit of HTML viewers. You’ll usually only see those characters in a CSS file if something like the CSS2 content property is used, if a URL in the style sheet contains the ampersand character, if a font name contains the character, or one of Microsoft’s CSS (JavaScript) expressions are used.
@VIPStephan: CDATA sections are not a replacement for the typical HTML commenting like this:
<style type="text/css">
<!--
…
-->
</style>
That kind of commenting is aimed at browsers that do not support the style element. If the browser does not, then it ends up interpreting the CSS as a comment so that it isn’t visible. On the other hand, CDATA sections are meant to prevent certain characters (as mentioned) from being parsed as markup.
Example 4 in your resource demonstrates a way to make this commenting practice compatible with an HTML-compatible XHTML document. It also points out that if a browser didn’t recognize the script tags and was a proper SGML parser, that the technique would fail to hide the script. (SGML is the language behind HTML; technically, any HTML parser should also be an SGML parser but in reality they are not. This is just like that any XHTML parser should also be an XML parser since XML is the language behind XHTML.)
Anyway, I would avoid the commenting method in my above example and in Example 4 and just do it the way jalarie did it (for XHTML only). You aren’t likely to encounter a browser that doesn’t understand the script or style elements.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.