Forum How do I...?

Conditional text alignment depending on # of lines

yet
we use something like

<div class="caption">Figure X: some caption</div>

For adding captions below images. The DIV should have a width of 2/3 of the width of the page (no issue) and centered if the caption is only one line long. For a caption spawning several lines should be left-aligned. Is there some magic for making the text-alignment conditional based on the number of lines within the caption? I think this is not possible...?!
mikeday
Not possible yet, no.
pjrm
(I only just saw this thread today, I thought I'd reply in case it's still relevant.)

The answer today might involve scripting.

However, consider instead using what was once (in the days before typesetters had to fit around the limitations of computers) a more common alignment strategy for captions, namely:

  text-align: justify;  text-align-last: center


(Note that this is equivalent to text-align:center for a caption of one line, and almost equivalent if two lines.)