5

Got an issue I've been trying to solve without much luck for a while across various projects.

I've got some divs with text inside that is centered with CSS using display: block and line-height. I also tried with padding and a fixed height. Typically, these are setup as either just headers, or sometimes buttons.

Either way, I always seem to have an offset on the top from vertical center in the mobile safari browser that I don't get in ANY web browser (it's perfectly vertically aligned in a desktop browser). I can alter the setting to center in the mobile browser, but this throws out all the other browsers and this is a responsive design.

Has anyone experienced this issue?

I've got -webkit-text-size-adjust: 100%; but that doesn't seem to be related to this issue.

So far my hack work around is to have devices only css which sets a different line-height, but as you can imagine, that's a horrible solution.

4

2 回答 2

2

当您对宽度和高度一无所知时,本文提供了有关使内容居中的许多不同选项的一些重要信息:

http://css-tricks.com/centering-in-the-unknown/

它很好地建立在 user1002464 的回答之上。

于 2013-09-06T00:42:02.973 回答
1

您可以使用display:table-cellandvertical-align:middle用于包含文本的 div

于 2013-05-02T18:50:53.580 回答