views:

72

answers:

3

Hello everyone,

I have a page with labels which are contained in a div, the labels has a variable with and i want to fill spaces between both with characters, dots or '-'.

For example.

My label text 1 ----------- Some Text Here.

My text 2 ----------------------- Another Text.

If you notice both text are justified (or at least i try), could be a problem of counting characters but character can have different width, any one knows a clean way of doing this programmatically in Asp.Net, css, jquery or anything else?

Update

................

Someone suggested in answers align both labels with css, but i think i will be having the same problem with the characters in the middle, which can be another label of course. Any thoughts?

Update

.................

Answer from Patrick is really close to the solution, but now hyphens are not shown in IE8, maybe there is a miss understand in one of my comments, it should work on IE7, IE8 and Firefox, only these browsers.

Thanks to everyone.

+3  A: 

You need to use CSS to adjust the layout of the two pieces of content. Either break up the label into two labels and apply css classes to each, or wrap each bit of text inside your label with a <span> tag and style them that way.

Filling empty space with characters to try to adjust the layout is not the correct approach, and wouldn't be recommended for the same reasons you don't format your text documents by adding space characters everywhere.

womp
Hi womp, thanks for your response, i understand for your answer that i need to separate this in 3 labels, right? but what happen with the label in the middle, i will be having the same problem. I mean, how many dots or '-' to add
dev-cu
Don't add any characters, that's the point. Use CSS to control the alignment and placement of your text, not more text.
womp
A: 
  1. Find the first instance of three spaces. I am assuming that this is the minimum number needed to constitute a "break"

  2. Find the first non-space character after that.

  3. Replace all the spaces between the index in #1 (+1) and the index in #2 (-1). That would give you the results above.

Check other answers for more clean ways to do it with CSS. That would be the cleanest way to display the text. Dashes look ghetto. :)

Craig
+5  A: 

Try this: http://jsfiddle.net/FpRp2/4/ (updated, now works in ie7)

The solution @Marcel gave to use a dashed border instead of text hyphens solved the final issue with IE7.

(Note, I've only tested in Safari, Firefox and Chrome so far.)

EDIT: IE8 works. Working on a fix for IE7.

HTML

<div class='outer'>
    <div class='container'>
        <div class='filler'></div>
        <span class='label'>some label</span>
        <span class='text'>some text</span>
    </div>
    <br>
    <div class='container'>
        <div class='filler'></div>
        <span class='label'>some other label</span>
        <span class='text'>some other text</span>
    </div>
</div>

CSS

.outer {
    display: inline-block;
    *display: inline;
    zoom: 1;
    position: relative;
    clip: auto;
    overflow: hidden;
}
.container {
    position: relative;
    text-align: right;
    white-space: nowrap;
}
.filler {
    position: absolute;
    left: 0;
    right: 0;
    border-bottom: 1px dashed #333;
    height: 50%;
}
.label {
    background: white;
    float: left;
    margin-right: 20px;
    padding-right: 4px;
    position: relative;
}
.text {
    background: white;
    padding-left: 4px;
    position: relative;
}
patrick dw
your are right, it works in Firefox, how to make it work in IE7, which fix?, i only need this two browsers, thanks for your answer.
dev-cu
@dev-cu: I'm trying to figure out the proper IE7 fix. CSS hacks are not my strength. I'll keep tinkering. :o)
patrick dw
I don't want to nit-pick too much, as your solution looks nice, but I would have used spans for those texts (`.filler`, `.label`, `.text`).
Marcel Korpel
@Marcel - I would welcome any thoughts. I agree, spans make a little more sense given the content. Any thoughts on the IE7 fix? I'm not making much progress.
patrick dw
The `float:right` on the `.text` is forcing the width of the `.container` all the way to the right.
patrick dw
Hmm, I tried it with `span`, but I'm muddling through those `display` settings. Regarding IE 7: sorry, no IE 7 here at the moment. BTW, isn't it nicer to use a dashed border (moved upwards using relative positioning) as a filler?
Marcel Korpel
Updated the example. I'm a step closer. Almost works. Just an issue with the height of each row. @Marcel - Your idea about the dashed border may be the solution.
patrick dw
@dev-cu: Works now. Instead of doing `float:right` for the text on the right, I did `text-align` right for the `.container`. Then the suggestion @Marcel gave to use a dashed border instead of hyphens took care of a line height issue. Thanks Marcel. :o)
patrick dw
@patrick: First, thanks for your time, solution is really closer, but is just me or hyphens or border is not shown in IE7
dev-cu
@dev-cu: I just tested in IE7 and IE8. Both work well for me. Are you viewing the version in jsFiddle? http://jsfiddle.net/FpRp2/4/
patrick dw
ok, i tried this, add to .filler left: -100%; top:-8px; width:100%; now hyphens are shown in IE8 but not in Firefox, :-(
dev-cu
@dev-cu: Are you testing in the jsFiddle, or on your page? The jsFiddle displays properly for me in IE8.
patrick dw
@patrick: i am testing in a local page only with that style and html, and it doesn't work on IE8, anyway i added to .filler this attributes top: -8px; height: 23px; width:100%; and now works in both browser, what do you think?
dev-cu
@dev-cu: You perhaps didn't have your DOCTYPE set on your test page? `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">` for example. The exact code from the jsFiddle works for me as long as the DOCTYPE is set.
patrick dw