将div与动态大小的页面中心对齐

Nic*_*ckF 2 html css android webview ios

我看到了很多关于如何将div居中到页面中间的示例,但在所有示例中,div的大小都是固定的.
如何将div放在div高度未知大小的页面中心?
(中间的灰色div)

我的代码:

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <style>
            html,body{
                margin: 0;
                padding: 0;
                border: 0;
            }
            body{
                background-color: transparent; 
                overflow: hidden;
                font-family: "Helvetica"
                    ;
                    color: #359115;
                    font-weight:bold;
                    }

                    #wrapper {
                        position: absolute;
                        width: 100%;
                        height: 100%;
                        text-align: center;
                    }

                    #container {
                        background-color: #dddddd;
                        /*height: 100%;
                        widows: 100%;*/
                        margin: 0,auto;
                        text-align: center;
                    }



        </style>
    </head>
    <body>
        <div id="wrapper">
            <div id="container" align="center">
                <span class="currency">$ </span><span class="integer">4,080,048.</span><span class="decimal">00</span>
            </div>
        </div>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

编辑:

我需要在Android和IOS中使用webView,因为这些数字总是出现在浏览器的顶部.
注意:浏览器不是全屏!

截图是我的另一个问题

fca*_*ran 5

如何将div放在div高度未知大小的页面中心?

一个涉及2d变换的简单解决方案(X轴和Y轴的负平移值):

http://jsbin.com/itifad/1/edit

CSS

div {
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -moz-transform: translate(-50%, -50%);    /* Older Gecko browser */
  -ms-transform: translate(-50%, -50%);     /* IE9+ */
  -o-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
Run Code Online (Sandbox Code Playgroud)

这就是全部:不需要使用javascript或嵌套元素,来定义父容器的高度或使用棘手的显示属性.

进一步参考:http://css-tricks.com/centering-percentage-widthheight-elements/

浏览器支持:http://caniuse.com/transforms2d(不工作IE<=8)