I have a title and a link that have to fit in a very specific width and height. If the title is too long I adjust the margin above with a class so it moves up. I am doing this with
<h2 <? if(strlen($report['title']) > 26) echo 'class="longer"';?>>Title text</h2>
26 is a value I played with that fit most title examples. However there is a rogue title that although > 26 in length, is using smaller words like "in" and "the" so it does not break into 3 lines like it's other >26chars counterparts.
In the screenshot you see 1. The "long but not 3 lines" example, 2. A normal length, 3. A longer, adjusted length.
How do you handle this type of scenario? (These divs are left aligned so the "See full report" must remain in the same vertical position across all examples before anyone recommends just making it flow after the title).
I resorted to using JS in the end (jQuery) to count line lines, but Chrome incorrectly reports some as 3 lines when infact it is only 2, Firefox worked as expected. The Chrome issue is strange because despite having exactly same heights, 1 would report as 2 lines, the other 3. Very odd.
var divHeight = $(this).outerHeight();
var lineHeight = parseInt($(this).css('lineHeight'));
var lines = Math.round(divHeight / lineHeight);
if(lines > 2)
$(this).addClass('longer');
I also tried basing it on height but again, browser/platform differences made this pretty unreliable.