By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,739 Members | 1,059 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,739 IT Pros & Developers. It's quick & easy.

vertical alignement of character in text

P: n/a
I have a group of links prefixed with the arrow as follows:
»link1 »link2 »link3

I would like the arrows to be vertically aligned middle of the text, like
as if they were bullets of list item, but without linebreaks.

The text would be quite large and set to a percentage, eg. 200%, so
there's no way of knowing the exact pixel height.

If all items were simply placed after each other, the arrow would naturally
fall to the baseline of the text.

Using an old table, the align middle effect could be done as follows:
<table><tr>
<td> » </td><td> link1</td
<td> » </td><td> link2 </td>
<td> » </td><td> link3 </td>
</tr></table>

But a table isn't very flexible, as linebreaks do not occur if the window
is scaled down to less than the combined width of all links.

What CSS way(s) are there which can do this better?
Jul 20 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
michael <no****@example.com> wrote:
I have a group of links prefixed with the arrow as follows:
»link1 »link2 »link3
The character » is not an arrow but a quotation markup. Common as it
might be to use it as an arrow symbol, I would recommend using either a
real arrow character or an image. On the other hand, arrows have the
connotation of _direction_, so is this really a "breadcrumb" as it would
suggest to many people?
I would like the arrows to be vertically aligned middle of the text,
like as if they were bullets of list item, but without linebreaks.


Assuming that the links are in a block element with no other content,
i.e. something like

<div class="nav">
»<a href="...">link1</a>
»<a href="...">link2</a>
»<a href="...">link3</a>
...
</div>

then you could use a little trick like

..nav a { vertical-align: -0.2ex; }

which lowers the links so that the quotation marks appear as if (roughly)
middle aligned with them.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Jul 20 '05 #2

P: n/a
michael wrote:
I have a group of links prefixed with the arrow as follows:
»link1 »link2 »link3

I suggest using an image; you have a lot more control over the
appearance and positioning.
The quote marks shown above may not sit on the baseline in all fonts.
So adjusting the text to match may work for your system but not others.

--
jmm dash list at sohnen-moe dot com
(Remove .TRSPAMTR for email)
Jul 20 '05 #3

P: n/a
On 17 Jun 2004 23:16:54 GMT, James Moe <jm***************@sohnen-moe.com>
wrote:
michael wrote:
I have a group of links prefixed with the arrow as follows:
»link1 »link2 »link3

I suggest using an image; you have a lot more control over the
appearance and positioning.
The quote marks shown above may not sit on the baseline in all fonts.
So adjusting the text to match may work for your system but not others.


In what way would you suggest using an image improves the chances of a
more suitable positioning, seeing that some browsers don't resize images
with the text?

Using a chracter re-positioned relative to the font size is going to give
a better appearance IMO.
Jul 20 '05 #4

P: n/a
Neal wrote:
Using a chracter re-positioned relative to the font size is going to give
a better appearance IMO.


I agree it would be better to use a text character for resizin purposes,
whilst I guess an image could simply be align=middle, how exactly could I
re-position the » character relative to the font size?

Jul 20 '05 #5

P: n/a
On Fri, 18 Jun 2004 16:11:48 +0200, michael <no****@example.com> wrote:
Neal wrote:
Using a chracter re-positioned relative to the font size is going to
give
a better appearance IMO.


I agree it would be better to use a text character for resizin purposes,
whilst I guess an image could simply be align=middle, how exactly could I
re-position the » character relative to the font size?


Like Jukka said, using a font-size-based measurement like ex or em. You
did see Jukka's response? I quote it below.

"Assuming that the links are in a block element with no other content,
i.e. something like

<div class="nav">
»<a href="...">link1</a>
»<a href="...">link2</a>
»<a href="...">link3</a>
...
</div>

then you could use a little trick like

..nav a { vertical-align: -0.2ex; }

which lowers the links so that the quotation marks appear as if (roughly)
middle aligned with them."
Jul 20 '05 #6

P: n/a
> Like Jukka said, using a font-size-based measurement like ex or em. You
did see Jukka's response? I quote it below.


Yes I read it, but I also read somewhere that ex is badly approximated by
browsers, but maybe that's old information. I'll test. Thanks for the info.

Jul 20 '05 #7

P: n/a
michael <no****@example.com> wrote:
- - I also read somewhere that ex is badly approximated by
browsers, but maybe that's old information


It is still true in the sense that browsers generally do not implement ex
as it should be implemented, as the font's x height value. Instead they
treat as 0.5em. But although this is incorrect - the x height varies by
font, so that for serif fonts, ex is usually smaller than 0.5em, for
sans-serif fonts it is usually larger than 0.5em - it gives reasonable
results in cases like this.

In effect, one can use ex when it is acceptable that browsers implement
it as 0.5em and desirable that they implement it correctly as the
x height.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Jul 20 '05 #8

P: n/a
Neal wrote:

I suggest using an image; you have a lot more control over the
appearance and positioning.


In what way would you suggest using an image improves the chances of a
more suitable positioning, seeing that some browsers don't resize images
with the text?

The image would not necessarily re-size, of course, but would at least
be positioned in the middle as desired. Using the text arrow assumes the
user's font will actually display what the OP thinks will be displayed.

--
jmm dash list at sohnen-moe dot com
(Remove .TRSPAMTR for email)
Jul 20 '05 #9

P: n/a
On Fri, 18 Jun 2004 21:34:53 +0000 (UTC), Jukka K. Korpela
<jk******@cs.tut.fi> wrote:
michael <no****@example.com> wrote:
- - I also read somewhere that ex is badly approximated by
browsers, but maybe that's old information


It is still true in the sense that browsers generally do not implement ex
as it should be implemented, as the font's x height value. Instead they
treat as 0.5em. But although this is incorrect - the x height varies by
font, so that for serif fonts, ex is usually smaller than 0.5em, for
sans-serif fonts it is usually larger than 0.5em - it gives reasonable
results in cases like this.

In effect, one can use ex when it is acceptable that browsers implement
it as 0.5em and desirable that they implement it correctly as the
x height.

Question: if -0.2ex might be rendered differently, wouldn't -0.1em yield
more predictable results, and therefore be more desirable? Especially when
the actual pixel height of 1em would be under 20px, the actual center of
the ex-height wouldn't vary more than a pixel... or am I missing
something? And what is it? ;)
Jul 20 '05 #10

P: n/a
Neal <ne*****@yahoo.com> wrote:
Question: if -0.2ex might be rendered differently, wouldn't -0.1em
yield more predictable results, and therefore be more desirable?
More predictable, yes; but not necessarily more desirable, if -0.2ex
describes better what you really want.
Especially when the actual pixel height of 1em would be under 20px,
the actual center of the ex-height wouldn't vary more than a pixel...


In this particular case, dealing with a specific character (which IMHO
should not be used instead, since it is a punctuation mark [sorry for my
typo "markup" in my original reply]), it seemed, after some quick tests,
that -0.2ex might be close to the desired appearance. I tend to think
such things in terms of the x height, and therefore used the ex unit. In
this case it would indeed rarely matter whether one uses -0.2ex or
-0.1em. But I think that typical when you set the vertical-align property
for a piece of text (e.g., for <sub> or <sup> elements to get a more
consistent appearance), ex better relate to the goal. For example, to set
some character in a suitable superscript position, I would rather
describe "suitable" in terms of the x height than the font height.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Jul 20 '05 #11

P: n/a
> In effect, one can use ex when it is acceptable that browsers implement
it as 0.5em and desirable that they implement it correctly as the
x height.


I tested this, across browsers and the result is fine. Thanks for the info!

Jul 20 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.