I am using collection-repeat (from ionic framework) to display a list of envelopes in my app. Works great, but I would like to fine-tune the layout. Each envelope is 150px by 80px and it flows (so wider displays will have 3 or 4 or 5 columns).
I've calculated the amount of padding I need to add to the left side in order to center the grid, but I can't figure out how to update the DOM (I'd rather not use jQuery). Any suggestions?
Here is my HTML template:
<ion-content has-tabs="true">
<div class="envelope-wrapper"
collection-repeat="envelope in envelopes"
collection-item-width="150"
collection-item-height="80">
<div class="envelope" style="background: {{ envelope.color }}">
<div class="name">{{ envelope.name }}</div>
<div class="amount">{{ envelope.amount | humanMoney }}</div>
</div>
</div>
</ion-content>
Here is my SCSS:
.envelope-wrapper {
padding: 4px;
height: 80px;
width: 150px;
.envelope {
height: 100%;
width: 100%;
background: #eee;
border: 1px solid rgba(0, 0, 0, .35);
border-bottom: 1px solid rgba(0, 0, 0, .75);
box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, .5), 0 1px 3px #ccc;
.name { ... }
.amount { ... }
}
}
And here is what it looks like when rendered. Notice all the white space on the right side. As I said, I've already calculated how wide that space is and I know the number of pixels I need to pad on the left, but I just can't figure out how to add left padding.
Just place another wrapper div as parent of .envelope-wrapper, you're trying to style directly in the collection item, which has a position: absolute; attribute, which positions the element in a pre calculated part of the DOM not affecting the sibling elements so padding is applied but not as desired. Let the width of each collection element be 50% and work inside of it.
<!-- Completed the code with the updated directives and attributes -->
<ion-content has-tabs="true">
<ion-list>
<!--if you want a 10px margin bottom-->
<ion-item collection-repeat="envelope in envelopes" item-width="50%" item-height="90">
<div class="envelope-wrapper"
<div class="envelope" style="background: {{ envelope.color }}">
<div class="name">{{ envelope.name }}</div>
<div class="amount">{{ envelope.amount | humanMoney }}</div>
</div>
</div>
</ion-item>
</ion-list>
</ion-content>