views:

47

answers:

2

I'm working on an English/Thai phrase app. In addition to displaying both English and Thai text, I need to display Phonetic text. The Phonetic text is English characters with arrows indicating inflection above the syllables. Example:

knuckles

↘      ↑

kaw-new

In that example, the falling arrow should be centered above "kaw" and the up arrow should be centered above "new".

The HTML currently looks like:

<div id="2173" class="eng">knuckles</div>
<div id="2173" class="phonetic"><div class="arrow">↘</div><div class="text">kaw-</div><div class="arrow">↑</div><div class="text">new</div></div>

The CSS currently looks like:

.arrow {
    margin-left:1em;
    padding-bottom:1em;
    display:inline;
    position:absolute;
}

.text {
    display:inline;
    padding-top:0;
    margin-top:1em;
    position:relative;
    float:left;
}

That's the HTML and CSS I've come up with, but I can't seem to get it to display the way I want. It's almost right in Safari, but not at all right in Firefox (not bothering with IE testing as the app uses HTML5 localStorage which IE doesn't support). The HTML is being dynamically written using JavaScript, so I'm open to suggestions there. Also, I'm not using a monospaced font, so somehow I need to calculate the arrow's location in relation to the word it goes above.

If anyone has any suggestions I'd love to hear them.

+2  A: 

How about

.syllable {
    display:inline-block;
}
.syllable span {
    display:block;
    text-align:center;
}

<span class="syllable"><span>↘</span>kaw</span>
-<span class="syllable"><span>↑</span>new</span>

This centers the arrow above each syllable. You should really make each syllable its own container (span is fine, but make it inline-block), because that's the most logical way to do it.

The clue here is that the inner span is a block container, which automatically takes up the whole line, forcing the text to start on the next line.

Tor Valamo
Outstanding! Answered about 2 minutes after my post and works perfectly. Thank you!
dosboy
Div-inside-span isn't valid HTML tho... quick fix: turn the div into another span, and use `display: block` on it. Or you could even get away with just putting a `<br>` between the arrow and syllable, and centering the whole span.
bobince
@bobince - good point. changed it. I won't recommend a <br> inside a span though, because if the css changes, the layout of that section will change drastically (more so than if the span just drops down in front of the syllable). The point isn't really the changing css though, but that it's unsemantic. If you read the line it will look like it should be a line break there, which isn't the case.
Tor Valamo
You guys are animals! I've updated my code to the currently posted version. Thanks again.
dosboy
A: 

How about throwing them in to a 2x2 table with centered alignment?

I'm pretty sure that cross-browser, that will give you the best behavior.

Yuval A
A table would break the flow though... you'd have to `display: inline-table` to get it to work inline.
bobince