【发布时间】:2019-06-02 05:20:39
【问题描述】:
对于使用 Angular、Angular Material 和 Flex-Layout 的个人项目,我正在尝试实现 Bring! App 使用的类似布局:
拥有不同大小的图像(并非全部为正方形),我希望将它们按比例居中并允许在它们下方放置一些文字。 我有以下模板和 scss 样式:
<div fxLayout="row" fxLayoutGap="5px" class="cards-container">
<div class="item-card">
<div class="image">
<img src="../../../../assets/icons/apple.png" alt="Mela" />
</div>
<span class="item-name">Mela</span>
<span class="description">12</span>
</div>
<div class="item-card">
<div class="image">
<img src="../../../../assets/icons/milk.png" alt="Latte" />
</div>
<span class="item-name">Latte</span>
<span class="description">1 description comes here, must be hidden if long text</span>
</div>
</div>
//---------------------------------------------------
.cards-container {
flex-wrap: wrap;
.item-card {
display: flex;
flex-direction: column;
justify-items: end;
color: white;
width: 7em;
height: 7em;
text-align: center;
background-color: darkslategray;
margin: 5px 0;
img {
width: 40%; // TODO: how to scale?
height: 40%;
}
.text-container {
display: flex;
flex-direction: column;
.item-name {
display: inline-block;
font-size: 1.1em;
}
.description {
width: 99%;
font-size: 0.8em;
text-align: center;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
display: inline-block;
}
}
}
}
但是图像不会按比例缩小以保持与其他图像的比例,尤其是窄而长的图像。
【问题讨论】:
-
请提供minimal reproducible example,当我们可以实际尝试代码时,css问题会更快解决。
-
这是一个旁注,但您想将您的 img 路径更改为:
src="assets/icons/apple.png"否则它们将不会在产品构建中找到 -
完全正确的mchl18,我还在本地测试,但我会尽快修复它。
标签: css angular sass flexbox angular-material