I'm trying to vertically and horizontally center content of an unknown height in a UIWebView.
What I have right now works great in Safari:
However, it does not look right when presented in a UIWebView:
Any ideas how to get this to work? One thing I cannot do is set the viewport meta, because this needs to work when presenting the UIWebView in a modal view controller on iPad, where it is not the full width of the screen:
<meta name="viewport" content="width=device-width;initial-scale=1.0;maximum-scale=1.0;"/>
Best Answer
I tried your example and it works fine in an UIWebView. I don't know how you load your HTML / CSS. Are you sure that the CSS is loaded correctly? Have you set the frame of your UIWebView?
Here is the code that works for me. I set the frame of the UIWeb smaller than the screen size because you mentioned presenting it modally.