我正在构建一个聚合物应用程序来显示学生的详细信息。 我想用每个学生的姓名和形象动态制作纸质卡片。 现在我通过复制同一张卡制作了5张卡片。但是每张纸卡都显示在同一行上。我希望每行显示4张纸卡。
<dom-module id="card-view">
<template>
<style>
/* local styles go here */
:host {
display: inline-block;
}
.card {
margin-left: 5px;
margin-right: 5px;
}
</style>
<style is="custom-style">
.flex {
@apply(--layout-horizontal);
text-align: justify;
-ms-text-justify: distribute-all-lines;
text-justify: distribute-all-lines;
width:100%;
}
</style>
<!-- local DOM goes here -->
<div class="container flex">
<div class="card">
<paper-card heading="Emmental" image="http://placehold.it/350x150/FFC107/000000">
<div class="card-content">
Emmentaler or Emmental is a yellow, medium-hard cheese that originated in the area around Emmental, Switzerland. It is one of the cheeses of Switzerland, and is sometimes known as Swiss cheese.
</div>
<div class="card-actions">
<paper-button>Share</paper-button>
<paper-button>Explore!</paper-button>
</div>
</paper-card>
</div>
<div class="card">
<paper-card heading="Emmental" image="http://placehold.it/350x150/FFC107/000000">
<div class="card-content">
Emmentaler or Emmental is a yellow, medium-hard cheese that originated in the area around Emmental, Switzerland. It is one of the cheeses of Switzerland, and is sometimes known as Swiss cheese.
</div>
<div class="card-actions">
<paper-button>Share</paper-button>
<paper-button>Explore!</paper-button>
</div>
</paper-card>
</div>
<div class="card">
<paper-card heading="Emmental" image="http://placehold.it/350x150/FFC107/000000">
<div class="card-content">
Emmentaler or Emmental is a yellow, medium-hard cheese that originated in the area around Emmental, Switzerland. It is one of the cheeses of Switzerland, and is sometimes known as Swiss cheese.
</div>
<div class="card-actions">
<paper-button>Share</paper-button>
<paper-button>Explore!</paper-button>
</div>
</paper-card>
</div>
<div class="card">
<paper-card heading="Emmental" image="http://placehold.it/350x150/FFC107/000000">
<div class="card-content">
Emmentaler or Emmental is a yellow, medium-hard cheese that originated in the area around Emmental, Switzerland. It is one of the cheeses of Switzerland, and is sometimes known as Swiss cheese.
</div>
<div class="card-actions">
<paper-button>Share</paper-button>
<paper-button>Explore!</paper-button>
</div>
</paper-card>
</div>
<div class="card">
<paper-card heading="Emmental" image="http://placehold.it/350x150/FFC107/000000">
<div class="card-content">
Emmentaler or Emmental is a yellow, medium-hard cheese that originated in the area around Emmental, Switzerland. It is one of the cheeses of Switzerland, and is sometimes known as Swiss cheese.
</div>
<div class="card-actions">
<paper-button>Share</paper-button>
<paper-button>Explore!</paper-button>
</div>
</paper-card>
</div>
<div class="card">
<paper-card heading="Emmental" image="http://placehold.it/350x150/FFC107/000000">
<div class="card-content">
Emmentaler or Emmental is a yellow, medium-hard cheese that originated in the area around Emmental, Switzerland. It is one of the cheeses of Switzerland, and is sometimes known as Swiss cheese.
</div>
<div class="card-actions">
<paper-button>Share</paper-button>
<paper-button>Explore!</paper-button>
</div>
</paper-card>
</div>
</div>
</template>
<script>
Polymer({
is: 'card-view',
});
</script>
</dom-module>
答案 0 :(得分:0)
没试过,但这可能会做你想要的:
:host {
@apply(--layout-horizontal);
@apply(--layout-wrap);
}
.card:nth-of-type(4n) {
flex-basis: 100%;
}
答案 1 :(得分:0)
这可以使用iron-flex-layout-classes
元素来实现。
我们使用<style include="iron-flex iron-flex-layout">
标记包含了我们需要的类。为了限制同一行上卡的最大数量,我们将:host
类设置为max-width
只有足够大,以便在同一行上有四张卡。包含卡片的div
包含以下类<div class="container flex layout horizontal wrap">
。有了这些,我们实现了水平布局,当它不再适合内部元素时会包裹。
下面的工作示例。将其作为全屏运行以更轻松地查看效果。
<!-- https://stackoverflow.com/questions/37050702/how-to-display-only-4-divs-in-1-row-polymer -->
<!doctype html>
<head>
<meta charset="utf-8">
<!---- >
<base href="https://polygit.org/components/">
Toggle below/above as backup when server is down
<!---->
<base href="https://polygit2.appspot.com/components/">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="polymer/polymer.html">
<link rel="import" href="iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="paper-button/paper-button.html">
<link rel="import" href="paper-card/paper-card.html">
</head>
<body>
<dom-module id="card-view">
<template>
<style include="iron-flex iron-flex-layout">
/* local styles go here */
:host {
display: block;
max-width: 1450px;
}
.card {
width: 350px;
margin-left: 5px;
margin-right: 5px;
}
</style>
<!-- local DOM goes here -->
<div class="container flex layout horizontal wrap">
<div class="card">
<paper-card heading="Emmental" image="http://placehold.it/350x150/FFC107/000000">
<div class="card-content">
Emmentaler or Emmental is a yellow, medium-hard cheese that originated in the area around Emmental, Switzerland. It is one of the cheeses of Switzerland, and is sometimes known as Swiss cheese.
</div>
<div class="card-actions">
<paper-button>Share</paper-button>
<paper-button>Explore!</paper-button>
</div>
</paper-card>
</div>
<div class="card">
<paper-card heading="Emmental" image="http://placehold.it/350x150/FFC107/000000">
<div class="card-content">
Emmentaler or Emmental is a yellow, medium-hard cheese that originated in the area around Emmental, Switzerland. It is one of the cheeses of Switzerland, and is sometimes known as Swiss cheese.
</div>
<div class="card-actions">
<paper-button>Share</paper-button>
<paper-button>Explore!</paper-button>
</div>
</paper-card>
</div>
<div class="card">
<paper-card heading="Emmental" image="http://placehold.it/350x150/FFC107/000000">
<div class="card-content">
Emmentaler or Emmental is a yellow, medium-hard cheese that originated in the area around Emmental, Switzerland. It is one of the cheeses of Switzerland, and is sometimes known as Swiss cheese.
</div>
<div class="card-actions">
<paper-button>Share</paper-button>
<paper-button>Explore!</paper-button>
</div>
</paper-card>
</div>
<div class="card">
<paper-card heading="Emmental" image="http://placehold.it/350x150/FFC107/000000">
<div class="card-content">
Emmentaler or Emmental is a yellow, medium-hard cheese that originated in the area around Emmental, Switzerland. It is one of the cheeses of Switzerland, and is sometimes known as Swiss cheese.
</div>
<div class="card-actions">
<paper-button>Share</paper-button>
<paper-button>Explore!</paper-button>
</div>
</paper-card>
</div>
<div class="card">
<paper-card heading="Emmental" image="http://placehold.it/350x150/FFC107/000000">
<div class="card-content">
Emmentaler or Emmental is a yellow, medium-hard cheese that originated in the area around Emmental, Switzerland. It is one of the cheeses of Switzerland, and is sometimes known as Swiss cheese.
</div>
<div class="card-actions">
<paper-button>Share</paper-button>
<paper-button>Explore!</paper-button>
</div>
</paper-card>
</div>
<div class="card">
<paper-card heading="Emmental" image="http://placehold.it/350x150/FFC107/000000">
<div class="card-content">
Emmentaler or Emmental is a yellow, medium-hard cheese that originated in the area around Emmental, Switzerland. It is one of the cheeses of Switzerland, and is sometimes known as Swiss cheese.
</div>
<div class="card-actions">
<paper-button>Share</paper-button>
<paper-button>Explore!</paper-button>
</div>
</paper-card>
</div>
</div>
</template>
<script>
Polymer({
is: 'card-view'
});
</script>
</dom-module>
<card-view></card-view>
</body>