css - 如何使css具有每行始终具有相同高度的反应列
问题描述
如何制作具有 6 列、3 列、1 列的反应式引导程序,但当浏览器大小发生变化时,列的高度始终相同?
角组件
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-tiles',
templateUrl: './tiles.component.html',
styleUrls: ['./tiles.component.scss']
})
export class TilesComponent implements OnInit {
superTotalData1: any = [];
superTotalData2: any = [];
tilePlannedBenefit = 'Planned Benefit';
tileMonthUpdated = '# Month Updated';
tileNotOnTrack = '# Not on Track';
tileBlownOut = '# Blown Out';
tileSlipped = '# Slipped';
tileReforecasted = '# Reforecasted';
tilePlannedCost = 'Planned Cost';
tileTotalAfe = 'Total AFE Amount';
tileAfeSpend = 'AFE Spend %';
tileAfeForecast = 'AFE Forecast %';
tileCarryForward = 'Carry Forward';
tileUnspent = 'Unspent';
constructor() { }
ngOnInit() {
this.updateUI();
}
parseAmount(value = 0) {
if (value >= 1000 && value < 1000000) {
return `$${Math.ceil(value / 1000)}k`;
} else if (value >= 1000000) {
return `$${Math.ceil(value / 1000000)}M`;
} else if (value >= 1000000000) {
return `$${Math.ceil(value / 1000000)}B`;
} else if (value >= 1000000000000) {
return `$${Math.ceil(value / 1000000)}T`;
}
return `$${Math.ceil(value)}`;
}
myYAxisTickFormatting(val) {
return '$' + val;
}
updateUI() {
this.superTotalData1 = [
new SuperTotalTile(this.parseAmount(564), this.tilePlannedBenefit),
new SuperTotalTile(String('Mar 2020'), this.tileMonthUpdated),
new SuperTotalTile(String(3), this.tileNotOnTrack),
new SuperTotalTile(String(0), this.tileBlownOut),
new SuperTotalTile(String(34), this.tileSlipped),
new SuperTotalTile(String(4), this.tileReforecasted),
new SuperTotalTile(this.parseAmount(345524), this.tilePlannedCost),
new SuperTotalTile(this.parseAmount(45345), this.tileTotalAfe),
new SuperTotalTile(`35%`, this.tileAfeSpend),
new SuperTotalTile(`6%`, this.tileAfeForecast),
new SuperTotalTile(this.parseAmount(4564), this.tileCarryForward),
new SuperTotalTile(this.parseAmount(4565), this.tileUnspent),
];
}
}
class SuperTotalTile {
constructor(
public value: string,
public label: string
) { }
}
的HTML
<div class="container">
<div class="row">
<div class="col-md-2 col-sm-4 col-xs-12" *ngFor="let superItem of superTotalData1">
<div class="super-tiles">
<div class="super-tile height-max">
<div class="super-tile-value">
{{superItem.value}}
</div>
<br>
<div class="super-tile-label">
{{superItem.label}}
</div>
</div>
</div>
</div>
</div>
</div>
CSS
.row [class*='col-'] {
text-align: center;
background-color: #cceeee;
background-clip: content-box;
margin-bottom: 5px;
}
.super-tiles{
display: flex;
.super-tile{
margin: 0 5px;
padding: 4px;
flex-grow: 1;
flex-basis: 0;
display: flex;
flex-direction: column;
border-radius: 4px;
box-shadow: 0 1px 5px #d2d2d2;
// align-items: center;
// justify-content: center;
color: #ffffff;
background: #008cba;
}
.super-tile-label{
font-size: 0.85em;
}
.super-tile-value{
font-size: 1.5em;
font-weight: bold;
// padding-left: 8px;
// text-align: right;
}
}
.header-tiles{
display: flex;
.header-tile{
margin: 0 5px;
padding: 2px;
flex-grow: 1;
flex-basis: 0;
display: flex;
flex-direction: column;
// border-radius: 4px;
// box-shadow: 0 1px 5px #d2d2d2;
// align-items: center;
// justify-content: center;
color: #000000;
background: #ffffff;
}
.header-tile-label{
font-size: 0.85em;
}
.header-tile-value{
font-size: 1.5em;
font-weight: bold;
// padding-left: 8px;
// text-align: right;
}
}
我创建了一个显示问题的示例(请参阅/examples/tiles/*)。这是一个 Stackblitz:
https://stackblitz.com/edit/bootstrap-rqqm3h?file=app/examples/tiles/tiles.component.ts
如果浏览器宽度很宽,则列的行为符合预期。如果我减小浏览器宽度,则在某一点上,列没有像行中的其他列那样填充整个行高。例如:深蓝色瓷砖应该是该行的浅蓝色瓷砖的高度。
例如:当它正确显示时
但是如果我稍微减小宽度(在它变为只有 3 列之前):
最后,当它减少到 3 列时,它的外观如何:
解释正确行为的示例文章:
和
https://medium.com/wdstack/varying-column-heights-in-bootstrap-4e8dd5338643
如示例所示:
- 除非浏览器宽度非常宽,否则列的每一行的蓝色平铺高度不同。
- 列之间有多余的空白我不知道如何最小化。
在所有浏览器宽度示例中,我正在努力研究使深蓝色与浅蓝色具有相同高度的值。非常感谢任何帮助。
解决方案
推荐阅读
- azure - 是否可以在时间序列洞察力中为用户友好的图表添加描述
- ruby - 无法通过 AWS-SES 和 Sidekiq 发送电子邮件
- locking - 为什么我们不在信号生产者而不是消费者检查条件变量?
- forms - Orbeon:如何显示来自文件系统资源的动态下拉值
- angularjs - AngularJs 组件绑定未在模板中呈现
- python - 要使用 OULAD 数据集,我如何加入或合并它们?
- sql - 在列上查找具有特定条件的行
- objective-c - 不小心从 XCODE 中删除 .XIB 文件
- scala - 在scala中调用http时出现Netcdf错误
- python - 将一个 numpy 数组传递给一个 numpy 函数数组