views:

101

answers:

2

I have the following markup:

<div class="blockSection">
<h5>Title of the section</h5>
...
</div>

now, the h5 for the .blockSection has a fixed height and a background image, 40px. For aligning the text vertically i always set the line-height same as the height, since the text wont break in 2 or more lines. But the problem is i'm using a font with font-face and i doesnt want to aligning vertically in Firefox, Safari on Mac. In windows IE looks good.

Anybody know the trick to make it right, without applying different line-height for browsers ?

A: 

It sounds like conditional comments would do the trick. Create an IE only stylesheet within one line-height and a main stylesheet with the line-height for the other browsers.

I know you don't want to set different line-heights for different browsers, but if IE is doing what you want and other browsers aren't, this is the best solution.

Pat
A: 

One solution for vertical centering (in non IE browsers) is using display: table-cell and vertical-align: middle on your h5 .

RoToRa
the result is the same …
blackhandr
Seems to work fine here: http://jsfiddle.net/ux2eE/
RoToRa
true, it does work perfectly with default web fonts, but with my font-face not :)
blackhandr
Hmm, I just tried with a Google web font and it's still ok: http://jsfiddle.net/ux2eE/2/ . I guess there is something wrong with your font in that case. Can you give any details about it? Possibly put it online?
RoToRa
http://jsfiddle.net/ux2eE/3/ you can see here
blackhandr
There must be something else influencing it. It seems perfectly centered for me in Firefox and Chrome: http://yfrog.com/jacenteredp
RoToRa
right :) but as i said on the first place the problem is with the OS X rendering, on Windows it just works super fine for me too!
blackhandr
Ah, I didn't realize it was Mac Firefox, too. It seems to be a Mac specific problem. I can't help you there. One last suggestion instead of real centering just give the element a top and bottom padding.
RoToRa