Jump to content

Word Filler


searls03

Recommended Posts

Ok, how would I make a line of text be a certain width......lets say 100px, but on one side I would like to display $product, on the other, $price. In between these would be a filler such as "......". what I need though is for the line to be a certain width, so that when it is typed in, lets say so that it looks like this:

 

product...................................$10

product12345.........................$10

 

so basically the two edges need to align, with "...." as fillers that may be a different number every time, how could I do this?

Link to comment
Share on other sites

Dude, it's easy. But I think, wisely be if you would use tables. Here's code:

 

<? // PHP Code
function ($before,$after) {
$name = $before;
$price = $after;
$totalLength = 200; // Total length of string
$dotsLength = $totalLength - strlen($name) - strlen($price); // Amount of dots
$dots = str_repeat(".",$dotsLength);
$result = $name.$dots.$price;
return $result;
}
?>

Link to comment
Share on other sites

Exactly. The only way it would work would be to use a fix-width font, same as when it's done in print. But the reality of the situation is that it's trying to force something on HTML that is generally handled in other ways in HTML - tables. Which is what Jessica was getting at.

Link to comment
Share on other sites

You should really, really, reallllly use a table. If you must do this though, here's an example in Javascript. You can't line up the dots perfect because it's not a fixed-width font, but the items and prices line up.

 

Demo Page: http://xaotique.no-ip.org/tmp/20/

 

HTML

<div class="list">
   <span>product</span>
   <div></div>
   <span>$10</span>
</div>
<br />
<div class="list">
   <span>product1234</span>
   <div></div>
   <span>$104</span>
</div>
<br />
<div class="list">
   <span>product12345678</span>
   <div></div>
   <span>$102344</span>
</div>
<br />
<div class="list">
   <span>productWhatever321</span>
   <div></div>
   <span>$1040</span>
</div>

 

Javascript / jQuery

// Allow Page To Load First
$(document).ready(function()
{
   var width  = 300; // Width of List
   var margin = 3;   // Margin (left/right) of Dots

   // Cycle The List Items
   $(".list").each(function()
   {
       // Float Children of List Left & Get Width
       var lw = $(this).children().css( "float", "left" ).width();

       // Add Our Dots To Size
       while ($(this).find("div:first").width() + lw < (width - (margin * 2)))
       {
           $(this).find("div:first").append(".");
       }

       // CSS for the Dots Div
       $(this).find("div:first").css(
       {
           "width": width - lw,
           "overflow-x": "hidden",
           "margin-left": margin,
           "margin-right": margin
       });
   });
});

Link to comment
Share on other sites

Or you could just take the dots out to the size of the list width then allow the overflow-x hidden attribute to kick in and you would end up with some partial dots to even it out, but you would still have some end in spaces. The width subtracting the margin will just have the right amount of dots without even using the overflow.

 

So, that's up to you, but easy and quick to change to your liking. If you would like to know how to use an actually table though, like you should be doing, let me know and I can give you an example of that, but I think I did what you wanted.

Link to comment
Share on other sites

Ok, how would I make a line of text be a certain width......lets say 100px, but on one side I would like to display $product, on the other, $price. In between these would be a filler such as "......". what I need though is for the line to be a certain width, so that when it is typed in, lets say so that it looks like this:

 

product...................................$10

product12345.........................$10

 

so basically the two edges need to align, with "...." as fillers that may be a different number every time, how could I do this?

 

With tables... for your tabular data... and a little styling, you could get this.

 

Here's the code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.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" media="all">
#wrap {
width:500px;
margin: 40px auto;
}
table {

}
table th {
background-color: lightBlue;
}
table td {
border-bottom:1px dotted red;
}
</style>
</head>

<body>
<div id='wrap'>
<table width="100%" cellpadding="2">
<tr>
<th align="left" scope="col">widget</th>
<th align="right" scope="col">price</th>
</tr>
<tr>
<td>whatever</td>
<td align="right">$1.00</td>
</tr>
<tr>
<td>whatever else</td>
<td align="right">$1.25</td>
</tr>
<tr>
<td>a third widget</td>
<td align="right">$11,000</td>
</tr>
</table>
</div>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.