无法使用css单位vw,vh或百分比设置高度

时间:2015-07-24 14:58:25

标签: android css cordova ionic-framework

我将div的宽度和高度分别设置为Ionic应用程序中视口宽度和高度的比例。这在我的计算机和Android 4.4设备上的资源管理器上运行得非常好。但是,这个属性似乎对Android 4.2没有影响(高度仅限于文本高度)。如果我将vh替换为%,它会继续使用v4.4,但仍然不在v4.2上。

这是我的代码

HTML

<body ng-app="starter">
    <ion-pane>
        <ion-content ng-controller="langController">

            ...

            <div id="language-selector" class="row">
                <h2>Idioma</h2>
            </div>

            ...

         </ion-content>
    </ion-pane>
</body>

CSS

#language-selector{
    height: 10vh !important;
    padding: 0;
    background-color: #d1d3d4;
}

如何在Android v4.2上完成此工作?

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

There was a similar question to this issue and the only solution seems to write a JS function to update the height for Android <4.4.

See also at CanIUse.

One JavaScript solution could be:

// set initial height
document.getElementById("myDiv").style.height = (window.innerHeight / 10) + "px";
// change height on every resize event
window.onresize = function () {
    document.getElementById("myDiv").style.height = (window.innerHeight / 10) + "px";
}

Try it out and resize the window height: http://jsfiddle.net/3eb68vf2/1/

Hope it helps!