A few days ago, a blog post: Mobile Web single-line text vertical center problem, the mobile web is less than 12px text center of the problem, and finally changed to 12px is almost solved the problem. But sometimes it may not be that optimistic, you can't change the font that was originally set to 10px to 12px. What should I do then?
As we all know, the mobile side for the HD screen display 1px border, there will be several methods, usually the best way is transform scale, and support fillet. Since a border can be scaled, the entire text area can also be scaled naturally.
For example, in the previous article it, CSS is this:
{ height: 20px; line-height: 20px; font-size: 10px; Border: 1px solid #000;}
Now that we want to scale, we'll do the 1px border, and then add another pseudo-class, and we'll multiply each size by 2 and then scale to half the original:
{ height: 40px; line-height: 40px; font-size: 20px; Border: 1px solid #000; -webkit-transform: Scale (0.5); Transform: Scale (0.5); -webkit-transform-origin: 100% 100%; transform-origin: 100% 100%;}
But, perhaps line-height on the mobile side really not how, the center effect is not good, changed to padding just better.
Then try a scheme to wrap a layer of parent elements in the outer layers of the element, and use display:table to implement them.
<class= "label-parent"> <class = "Label" > who are you </p></div>
. Label-parent{Display:Table;Height:40px;Line-height:40px;font-size:20px;Border:1px solid #000;-webkit-transform:Scale (0.5);Transform:Scale (0.5);-webkit-transform-origin:100% 100%;Transform-origin:100% 100%;}. Label{Display:Table-cell;vertical-align:Middle;}
This should be a more robust solution, write a layer, discard padding and line-height, and finally achieve a good result. There are children's shoes may be worried about the paste, it is true that the Chrome simulator will be paste, but the phone screen is mostly high-definition screen, almost no blurred situation.
Working on iOS and android4.x, but Android2.3 does not scale, search for a way to say that scales and translate together no matter, there is said viewport set, but it is useless, So you can give android2.x to set the non-scaled style, as long as the layout is not messy.
{ height: 20px; line-height: 20px; font-size: 10px; Border: 1px solid #000;}
How to know the system is 2x, in special CSS3 Scaling for andriod version less than 2.3 found a useful script:
var ua = navigator.useragent; if (Ua.indexof ("Android") >= 0 ) { var androidversion = parsefloat (Ua.slice ("Android ") +8)); if (androidversion <= 2.3) { // alert (' Andriod < 2.3 '); // Your code here }}
You can dynamically add a CSS to the style, and if you have only one tag you can also manipulate the DOM to change the style.
At this point, no perfect also don't want to toss again ...
The perfect solution for mobile web less than 12px text centered problem