Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Howto vertical-align a webview?

Hi,

I tried out several kinds of html code (with complete html, head, body tags - without html tags and just div style tag, ….) but I can't get a webview to vertical-align:middle the contained text….

webview.html =

<html><head><style>body { background-color: transparent; 
vertical-align:middle;}</style></head>
<body>My content...this is text...</body>
</html>

webview.html =

<div style="vertical-align:middle;">My content...this is text...</div>

can somebody give me an example how to vertically-align the content of a webview without using a local html file?
I put my html code into my webview with the webview.html setting.

Thanks for any help

— asked May 19th 2011 by Benjamin Sommerfeld
  • align
  • content
  • text
  • vertical-align
  • webview
0 Comments

3 Answers

  • Try :

    <div style="position:relative;top:50%">My content...this is text...</div>
    
    — answered May 19th 2011 by Kosso
    permalink
    0 Comments
  • Hi kosso, thanks for the answer, but that doesn't seem to work like vertical-align.
    I also have bulletpoint-lists with 5 to 10 entries which should be automatically aligned in the vertical middle of the webview…do you have any other idea?

    — answered May 19th 2011 by Benjamin Sommerfeld
    permalink
    0 Comments
  • Ha! I got it!
    This works:

    <table style=\"height:100%;\">
    <tr>
    <td style=\"vertical-align:middle;\">"+mytext+"</td>
    </tr>
    </table>
    

    Doesn't work with body, div or p tags.
    Pheew….. :)

    — answered May 19th 2011 by Benjamin Sommerfeld
    permalink
    2 Comments
    • If you're actually going to use an html table then you actually don't need to set the vertical alignment. Table cells are vertical-middle aligned by default…

      which can be overridden using valign in HTML : <td valign="top|bottom"> your text </td>

      — commented May 19th 2011 by Kosso
    • Thanks for your help, again. I'm going to use whatever it takes to lay out text vertically centered inside a webview :)

      — commented May 19th 2011 by Benjamin Sommerfeld
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.