Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong vertical align of text in Google Chrome browser

Tags:

I have problem with creating "button" element (text in inline-block container with border), because in some font-size text has wrong vertical-align (is not perfect middle).

I want to use Raleway (Google Web Font) and Bootstrap. Height of the text container is set by line-height.

I am testing it on Windows 7...

on Firefox (ver. 36) everything is perfect Firefox (ver. 36)

but the problem is on Google Chrome (ver. 41) Google Chrome (ver. 41)

Live preview: http://biznes-dynamit.pl/test/marcin-dobroszek/font/

Part of CSS code:

/*Bootstrap default style*/
* {
    box-sizing: border-box;
}
.btn {
    display: inline-block;
    vertical-align: middle;
}

/*custom style*/
body {
    font-family: "Raleway";
}
.btn {
    padding-top: 0;
    padding-bottom: 0;
    line-height: 16px;
    font-size: 11px; /*real height: 8*/
}
.btn-sm {
    font-size: 10px; /*real height: 7*/
    line-height: 15px;
 }
.btn-lg {
    font-size: 12px; /*real height: 8-9*/
    line-height: 16px; /*light, normal*/
 }

As you can see in Chrome preview in some font-size and font-weight text is go up relative container.

3x zoom sample, with font-size: 11px (line-height: 16px) and font-weight: semi-bold. wrong vertical space

Top and bottom space (between text and top/bottom border) should be the same: 4px, but as you can see top space has 3px and bottom has 5px.

Is it possible to fix this browser issue?

like image 573
Cichy Avatar asked Mar 31 '15 10:03

Cichy


People also ask

How do I change alignment in Chrome?

you can use any 'ctrl' but press 'shift' according to cursor position you need like for right press right shift otherwise press left shift.

How do you change the vertical text alignment?

1 Select the text you want to center between the top and bottom margins. 2 On the Page Layout tab, click the Page Setup Dialog Box Launcher. 3 Select the Layout tab. 4 In the Vertical alignment box, click Center 5 In the Apply to box, click Selected text, and then click OK.

Why is my font messed up in Chrome?

Go to Control Panel > Appearance and Personalization > Display > Adjust ClearType text (on the left). Check the box entitled “Turn on ClearType.” After going through a short wizard, this will fix some of the text rendering issues in Chrome. Enable "Disable accelerated 2D Canvas" in Chrome.


1 Answers

This very annoying problem is caused by chrome not taking text-transform: uppercase into account. Use the following to get correct centering in Chrome with all-caps text:

text-transform: lowercase;
font-variant: small-caps;

Fiddle: http://jsfiddle.net/fyvyB/76/

Works great for buttons, for other usecases you might have problems with the text being small-caps and not real caps.

Correct centering in chrome & ff

like image 106
Simon Epskamp Avatar answered Sep 22 '22 05:09

Simon Epskamp