css - Vertically and horizontally center HTML in UIWebView -
i'm trying vertically , horizontally center content of unknown height in uiwebview.
what have right works great in safari:
however, not right when presented in uiwebview:

any ideas how work? 1 thing cannot set viewport meta, because needs work when presenting uiwebview in modal view controller on ipad, not full width of screen:
<meta name="viewport" content="width=device-width;initial-scale=1.0;maximum-scale=1.0;"/>
i tried example , works fine in uiwebview. don't know how load html / css. sure css loaded correctly? have set frame of uiwebview?
here code works me. set frame of uiweb smaller screen size because mentioned presenting modally.
- (void)viewdidload { [super viewdidload]; nsstring *htmlstring = @"<html><head><style type='text/css'>html,body {margin: 0;padding: 0;width: 100%;height: 100%;}html {display: table;}body {display: table-cell;vertical-align: middle;padding: 20px;text-align: center;-webkit-text-size-adjust: none;}</style></head><body><p><strong>title</strong></p><p>a long explanation what's going on , that.</p><p><a href='#'>a link</a></p></body></html>"; uiwebview *webview = [[uiwebview alloc] initwithframe:cgrectmake(10.0, 10.0, 300.0, 400.0)]; [self.view addsubview:webview]; [webview loadhtmlstring:htmlstring baseurl:nil]; [webview release]; } 
Comments
Post a Comment