I am trying to display a collection (using collection-repeat) and embedded in a ion-scroll and i have the problem that i can not set the height (of the ion-scroll) using percentages. It only works if i set the size using px.
I was wondering how could i set the list (the collection repeat inside the ion-scroll) to fit in the 50% of the screen.
Firstly, did you set a parent container for the ion-scroll tags, if you did, does it have a height defined?
Secondly, ion-scroll is a tag only readable by angular, but when compiled into DOM, it generates a structure like…
<div class="ion-scroll">
<div class="scroll">
//your content is generated in here, where ".scroll" itself has no height(not defined in ionic css).
</div>
<div class="scroll-bar"></div>
</div>
Then this is totally reasonable because ion-content also create a scroll div to wrap your ionscroll. You should try to add following css to your app.
.scroll{height:100%}
Normally this hack work with me.
Feel free to ask further problems.
It’s pretty simple. In your main.html, you have your view, within that you have your nav title and buttons. Then, you have a <div> that acts as a container for both the <ion-scroll> and the <ion-content>, which are siblings. This <div> takes into account the size of the header and otherwise takes up the rest of the screen (see the style attribute). The ion-scroll and ion-content then take their size from the container div. Ion-scroll can be set to height: 50%, and it will take 50% from the top of the <div> The <ion-content>'s default style is to take up the entire size of its container. So we override that by setting top: 50% so that it starts half way down the container.
Note that both areas will scroll, and on iOS they will scroll/bounce regardless of whether or not the content overflows their areas (I think… I don’t actually do iOS development), which might make for a strange user experience. You might want to disable scrolling on the <ion-content> if that area stays stationary.
Why does it have to be ‘absolute’ the position of the parent div ? Doesnt it limit the position to set the ion-scroll if i want to set it at the bottom and using a relative position ?
A lot of thanks in advance,
PS: I think the ‘absolute’ position is very restrictive.
I’m not sure what you mean. The div needs to be absolute so that it takes up the entire size of its parent (and thus the entire screen). If you want the ion-scroll at the bottom, just switch it with the ion-content and change the necessary style attributes. Another way to go at this might be flexboxes.
in other words let the content you want to be scroll be loaded in a div, then wrap that div with the ionscroll. Have only height attribute in containing div.