I want to display a grid of items with top and bottom margins using iron-list but no results.I'm using polymer 2.0 and iron-list 2.0.16. The margins are not displayed but appear in devtools when i highlight any of the items in iron-list. I don't know what i'm not doing right.I tried fixing it but no success. ...
:host {
display: block;
padding: 10px;
}
.country {
height: 50px;
width: 300px;
background-color: white;
margin: 16px 0;
}
iron-list {
height: 100vh;
}
</style>
<data-story-data region="africa" countries="{{countries}}"></data-story data>
<iron-list items="[[countries]]" as="country" scroll-target="document" grid>
<template>
<div class="country">
<p>[[country.name]]</p>
</div>
<!--
<paper-card>
<div class="card-content">
<div>[[country.name]]</div>
</div>
<div class="card-actions">
<a href="[[rootPath]]detail/country/[[country.name]]/[[country.alpha2Code]]/about" tabindex="-1">
<paper-button raised>view</paper-button>
</a>
</div>
</paper-card>
-->
</template>
</iron-list>
...
what can i do to make the 16px top and bottom margins work. thanks in advance.
The list items are displaying 0px margins because iron-list
overrides them:
iron-list.html
<style>
/* ... */
#items > ::slotted(*) {
box-sizing: border-box;
margin: 0; /* Here */
position: absolute;
top: 0;
will-change: transform;
}
/* ... */
</style>
Try instead to wrap your cards in a container and use its padding instead of margin to obtain the spacing you want:
<style>
.country {
padding: 16px 0;
}
</style>
<iron-list items="[[countries]]" as="country" scroll-target="document" grid>
<template>
<div class="country">
<paper-card>
<div class="card-content">
<div>[[country.name]]</div>
</div>
<div class="card-actions">
<a href="[[rootPath]]detail/country/[[country.name]]/[[country.alpha2Code]]/about" tabindex="-1">
<paper-button raised>view</paper-button>
</a>
</div>
</paper-card>
</div>
</template>
</iron-list>