Non-breaking non-space in HTML
Asked Answered
O

18

11

I have a bowling web application that allows pretty detailed frame-by-frame information entry. One thing it allows is tracking which pins were knocked down on each ball. To display this information, I make it look like a rack of pins:

o o o o
 o o o
  o o
   o

Images are used to represent the pins. So, for the back row, I have four img tags, then a br tag. It works great... mostly. The problem is in small browsers, such as IEMobile. In this case, where there are may 10 or 11 columns in a table, and there may be a rack of pins in each column, Internet Explorer will try to shrink the column size to fit on the screen, and I end up with something like this:

o o o
  o
o o o
 o o
  o

or

o o
o o
o o
 o
o o
 o

The structure is:

<tr>
    <td>
        <!-- some whitespace -->
        <div class="..."><img .../><img .../><img .../><img .../><br/>...</div>
        <!-- some whitespace -->
    </td>
</tr>

There is no whitespace inside the inner div. If you look at this page in a regular browser, it should display fine. If you look at it in IEMobile, it does not.

Any hints or suggestions? Maybe some sort of &nbsp; that doesn't actually add a space?


Follow-up/Summary

I have received and tried several good suggestions, including:

  • Dynamically generate the whole image on the server. It is a good solution, but doesn't really fit my need (hosted on GAE), and a bit more code than I'd like to write. These images could also be cached after the first generation.
  • Use CSS white-space declaration. It is a good standards-based solution, but it fails miserably in the IEMobile view.

What I ended up doing

*hangs head and mumbles something*

Yes, that's right, a transparent GIF at the top of the div, sized to the width I need. End code (simplified) looks like:

<table class="game">
    <tr class="analysis leave">
        <!-- ... -->
        <td> <div class="smallpins"><img class="spacer" src="http://seasrc.th.net/gif/cleardot.gif" /><br/><img src="/img/pinsmall.gif"/><img src="/img/nopinsmall.gif"/><img src="/img/nopinsmall.gif"/><img src="/img/nopinsmall.gif"/><br/><img src="/img/pinsmall.gif"/><img src="/img/pinsmall.gif"/><img src="/img/nopinsmall.gif"/><br/><img src="/img/nopinsmall.gif"/><img src="/img/nopinsmall.gif"/><br/><img src="/img/nopinsmall.gif"/></div> </td>
        <!-- ... -->
    </tr>
</table>

And CSS:

div.smallpins {
    background: url(/img/lane.gif) repeat;
    text-align: center;
    padding: 0;
    white-space: nowrap;
}
div.smallpins img {
    width: 1em;
    height: 1em;
}
div.smallpins img.spacer {
    width: 4.5em;
    height: 0px;
}
table.game tr.leave td{
    padding: 0;
    margin: 0;
}
table.game tr.leave .smallpins {
    min-width: 4em;
    white-space: nowrap;
    background: none;
}

P.S.: No, I will not be hotlinking someone else's clear dot in my final solution :)

Onomastic answered 18/9, 2008 at 14:41 Comment(0)
M
26

You could try the css "nowrap" option in the containing div.

{white-space: nowrap;}

Not sure how widely that is supported.

Macaronic answered 18/9, 2008 at 14:49 Comment(3)
According to Qurksmode, it is supported by all browsersers except IE 5 quirksmode.org/css/whitespace.htmlWristwatch
Marking this as accepted, with the caveat that it doesn't work for IEMobile :(Onomastic
there's a typo, it should read: {white-space: nowrap} (without the dash)Interstate
B
4

Why not have an image for all possible outcomes for the pins? No Messing with layouts for browsers an image is an image

Generate them on the fly caching the created images for reuse.

Blanketyblank answered 18/9, 2008 at 14:43 Comment(3)
Looking at the page, that would be a lot of images.Lazybones
2^10 = 1024 images? It's a lot, but manageable. Bandwidth is perhaps a concern, especially on mobile devices.Kellene
It would indeed. There are 10! possible combinations, though some are technically kind of impossible. Actually, it would be more than that, because a different image is used if a spare is made vs. missedOnomastic
L
4

I've got around this type of issue in the past by dynamically creating the entire image (with appropriate pin arrangement) as a single image. If you are using ASP.NET, this is pretty easy to do with GDI calls. You just dynamically create the image with pin placement, then serve to the page as a single image. Takes all the alignment issues out of the picture (pun intended).

Leclerc answered 18/9, 2008 at 14:45 Comment(1)
This is built using GAE, and I am concerned about CPU quota usage... I suppose I could cache each image after generation... Something to think aboutOnomastic
F
4

What would make the most sense is changing out which image is displayed on the fly:

<div id="pin-images">
    <img src="fivepins.jpg" />
    <img src="fourpins.jpg" />
    <img src="threepins.jpg" />
    <img src="twopins.jpg" />
    <img src="onepin.jpg" />
</div>
Fossorial answered 18/9, 2008 at 14:53 Comment(0)
K
3

Since you are using images anyway, why not generate an image representing the whole layout on the fly? You can use something like GD or ImageMagick to do the trick.

Kataway answered 18/9, 2008 at 14:46 Comment(0)
C
3

Add a "nowrap" in your td tag...

Cladoceran answered 18/9, 2008 at 14:55 Comment(0)
P
2

Since you're going for maximum compatibility, consider generating a single image representing the frame.

If you're using PHP, you can use GD to dynamically create images representing the frames based on the same input that you would use to create the HTML in your question. The biggest advantage to doing this is that any browser which could display a PNG or GIF would be able to display your frame.

Polivy answered 18/9, 2008 at 15:20 Comment(0)
V
2

I figured out that there is a setting on the client where they can select the view as 1) Single Column, 2) Desktop View, and 3) Fit Window.

According to MSDN, the default is supposed to be to Fit Window. But my wife's IE Mobile phone was defaulting to a Single Column. So no matter what, it would wrap everything into a single column. If I switched to any of the other two options it looked fine.

Well, you can set this with a meta tag:

<meta name="MobileOptimized" content="320">

will set the page width to 320 pixels. But I don't know how to make it go to auto.

This does not work on BlackBerry's prior to v4.6 - you're stuck with single column unless the user manually changes to desktop view. With 4.6 or later, the following is supposed to work, but I haven't tested it:

<meta name="viewport" content="width=320">
Verve answered 31/12, 2008 at 8:20 Comment(1)
Awesome, thank you very much. For iPhone/iPod touch support, I am currently using this setting: <meta name="viewport" content="width = device-width">. Do you know if there is another way that I can tell the blackberries to act correctly? If not, I can leave my current solution, which should be ok.Onomastic
D
1

You might need an actual space immediately following the semi-colon in  

Dotson answered 18/9, 2008 at 14:44 Comment(0)
H
1

Try it with the <div> tag on the same line as <td>...</td>

Hydrocarbon answered 18/9, 2008 at 14:48 Comment(0)
G
1

I may have misunderstood what you are after but I think that you can do what I've done for logos on a map.

The map background tile is drawn then each image is told to float left and given some interesting margins so that they are positioned as I want them to be (view source to see how it's done).

Gascon answered 18/9, 2008 at 14:48 Comment(2)
I don't think this would help me keep the column wide enough to display all 4 images... would it? I will tryOnomastic
Oh, to keep it wide enough, you need to have the parent div have... style="width: Xpx;", that'll force it to be a certain width.Gascon
B
1

Use the word joiner character, U+2060 (i.e. &#x2060;)

Blemish answered 18/9, 2008 at 15:6 Comment(1)
That one inserts a square character in the WM 6.1 emulator I'm usingOnomastic
D
1

Do you have tried to define a width for the column? Like <td width="123px"> or <td style="width:123px">. And maybe also for the div ?

Detent answered 18/9, 2008 at 15:52 Comment(1)
yes, they are both set to width:4em, min-width:4em. The images are each set to max-width:1em; to size them.Onomastic
D
1

You can replace img with span and use a background image with each span, depending on a CSS class:

<p class="..."><span class="pin"></span><span>&nbsp;</span><span class="pin"></span>...
<p class="..."><span class="pin"></span><span>&nbsp;</span><span class="pin"></span>...
<p class="..."><span class="pin"></span><span>&nbsp;</span><span class="pin"></span>...
<p class="..."><span class="pin"></span><span>&nbsp;</span><span class="pin"></span>...

(Personally I think it's better to have four lines with a p tag instead of a single div with br.)

Then in CSS you can have something like this:

p.smallpins {
    margin: 0;
    padding: 0;
    height: 11px;
    font-size: 1px;
}
p.smallpins span {
    width: 11px;
    background-image: url(nopinsmall.gif);
    background-repeat: ...
    background-position: ...
}
p.smallpins span.pin {
    background-image: url(pinsmall.gif);
}
Detent answered 18/9, 2008 at 16:10 Comment(1)
It's a nice approach, but does not degrade gracefully if, for instance, a user has CSS turned off.Onomastic
Z
1
  • There isn't any nobr HTML tag; I am not sure how well-supported this is, though.
  • You could use CSS overflow:visible and non-breaking spaces between your elements (images), but no other white space in the HTML content for those lines.
Zhukov answered 18/9, 2008 at 18:46 Comment(0)
U
1

Have separate images for every possible arrangement of each row.

That would only require 30 images (16+8+4+2)

Uncompromising answered 19/9, 2008 at 15:28 Comment(1)
There are actually 3 states possible for each pin - knocked down on the first ball, knocked down on the second ball, and not knocked down. That raises the number of images to be pre-calculated by a good bit.Onomastic
N
0

Maybe this is just one case where you could use tables to enforce layout. It's not optimal, and I know you aren't supposed to use tables for things that aren't tabular, but you could do something like this.

<table>
<tr>
<td><img src="Pin.jpg"></td>
<td>&nbsp;</td>
<td><img src="Pin.jpg"></td>
<td>&nbsp;></td>
<td><img src="Pin.jpg"></td>
<td>&nbsp;</td>
<td><img src="Pin.jpg"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><img src="Pin.jpg"></td>
<td>&nbsp;</td>
<td><img src="Pin.jpg"></td>
<td>&nbsp;</td>
<td><img src="Pin.jpg"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><img src="Pin.jpg"></td>
<td>&nbsp;</td>
<td><img src="Pin.jpg"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><img src="Pin.jpg"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
Nagana answered 18/9, 2008 at 15:9 Comment(1)
Use a table - then you have two problems :-) This approach forces the space between images to be as wide as the images themselves, which is propably not what he wants.Wristwatch
N
-1

Would it not be easier if you do it like this?

<div id="container">
  <div id="row1">
    <img/><img/><img/><img/>
  </div>
  <div id="row2">
    <img/><img/><img/>
  </div>
  <div id="row3">
    <img/><img/>
  </div>
  <div id="row4">
    <img/>
  </div>
</div>

Whereby your CSS would handle the alignment?

.container div{
  text-align:center;
}
Nautilus answered 18/9, 2008 at 14:49 Comment(1)
Would this keep the browser from inserting a linebreak inside one of the divs though?Onomastic

© 2022 - 2024 — McMap. All rights reserved.