Forum Moderators: not2easy

Message Too Old, No Replies

price sheet - dot leaders between item, price

auto width price sheet

         

seenlihner

2:29 pm on Aug 14, 2007 (gmt 0)

10+ Year Member



I'm trying to find a way to format a price sheet so the item is justified to the left and the price is justified to the right but in between are "......" leading to the price. I understand using auto width will wrap the <div> around the text, but i don't know how to get the "....." to display the whole width between the item and the price.

Gibble

2:33 pm on Aug 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



create a div or something to stretch between the two items with the bottom border style set to dotted

vincevincevince

2:35 pm on Aug 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One method is to have the ...... running the entire length of the line (i.e. behind the text at both sides as well) and then setting a white background colour and appropriate margins on your text.

That means that the .... only shows between the lines.

The 'putting behind' can be done with CSS positioning or more easily by using a background image which is horizontally repeated.

seenlihner

2:45 pm on Aug 14, 2007 (gmt 0)

10+ Year Member



i wish i could and make the background color of the text white, but i can't set the color because there is a gradient background that i want to keep.

vincevincevince

2:48 pm on Aug 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This old thread may help [webmasterworld.com]

Xapti

5:45 am on Aug 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Best thing I can think of is something like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "//www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>variable width center elipsis</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type="text/css">
#a{float:left}
#bak{background-image:url('image.gif');height:1em;margin-left:100px;margin-right:100px}
#b{float:right}
</style>
</head>
<body>
<div id="a">this is A</div><div id="b">mojo B</div><div id="bak"></div>
</body>
</html>

You must have a fixed width of no elipsis (background image) for both sides though. This can be kept the same value for each entry (probably best. Also note you should use em instead of px), or you could tweak the width for each item, but that takes either lots of work, or some javascript.

Of course you could get a pretty much perfect effect if you could set the background colors to cover (then you could use all sorts of methods, and you wouldn't have to assign widths), but you said that wasn't realyl an option.

I think gibbles idea was great though; just set a bottom border around he whole thing (not just inbetween, because that can't really be done). The outcome will be that the line will go under the price and item names too, but I do not consider that a downside at all, just a special trait.

You may also want to consider usage of alternating background colors instead of the elipsis style. This is quite popular, and can be done nicely with CSS.

[edited by: Xapti at 5:49 am (utc) on Aug. 15, 2007]

Gibble

3:09 pm on Aug 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




<style type="text/css">
.row {
width: 50%;
margin: auto;
}

.dots {
padding: 0;
border-bottom: dotted black thin;
}

.product {
float: left;
margin: 0;
padding: 0;
}

.price {
float: right;
margin: 0;
padding: 0;
}
</style>

<div class="row">
<div class="product">longer product name</div>
<div class="price">$19,999</div>
<div class="dots">&nbsp;</div>
</div>

<div class="row">
<div class="product">product</div>
<div class="price">$19,999</div>
<div class="dots">&nbsp;</div>
</div>

<div class="row">
<div class="product">longer product name</div>
<div class="price">$19,990,000</div>
<div class="dots">&nbsp;</div>
</div>

<script>

function getElementsByClassName(classname, tagname, node) {
if(!node) node = document.getElementsByTagName("body")[0];
if(!tagname) tagname = "*";

var a = [];
var re = new RegExp('\\b' + classname + '\\b');
var els = node.getElementsByTagName(tagname);

for(var i=0,j=els.length; i<j; i++)
if(re.test(els[i].className))a.push(els[i]);

return a;
}

function fixDots() {
var row_divs = getElementsByClassName('row', 'div');

for (var i = 0; i < row_divs.length; i++) {
var div = row_divs[i];

var productDiv = getElementsByClassName('product', 'div', div)[0];
var priceDiv = getElementsByClassName('price', 'div', div)[0];
var dotsDiv = getElementsByClassName('dots', 'div', div)[0];

dotsDiv.style.marginLeft = productDiv.clientWidth;
dotsDiv.style.marginRight = priceDiv.clientWidth;
}
}

fixDots();
</script>