This is a migrated thread and some comments may be shown as answers.

Element size in Percentage

1 Answer 57 Views
HTML5, CSS, JavaScript
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Manuel
Top achievements
Rank 1
Manuel asked on 25 Nov 2015, 05:53 PM

Hello,

 I want to set the size of a div within my View to a certain percentage value via css. However, while this works in the Android-Simulator, on a device the height always resets to 0, so nothing is visible within the View-Element.

My Code:

CSS

#logo{
    top:2%;
    position: absolute;
    width:100%;
    height:height: 38%;
    background-image: url("../media/img/logo.png");
    background-size:contain;
    background-position: 50% 50%;
    background-repeat: no-repeat;
}
#imageText{
    position: absolute;
    top:45%;
    left:3%;
    width:94%;
    height: 55%;
    text-align: center;
    font-size: 24pt;
    color:white;
    overflow: auto;
}

HTML:

 <div data-role="view" data-title="Home" data-layout="main" data-model="APP.models.home">
    <div id="logo"></div>
    <div id="imageText" data-bind="text:text"></div>
</div>

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 30 Nov 2015, 09:08 AM
Hello Manuel,

This happens because there isn't a parent element to your element that has a fixed size. Height can be set in percentage only when there is a parent element with fixed size in the DOM. You can consider using a flexbox layout to arrange the elements in your view:
A Complete Guide to Flexbox

Regards,
Tsvetina
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
Tags
HTML5, CSS, JavaScript
Asked by
Manuel
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or