html - Div 是立即扩展而不是随着时间的推移?
问题描述
单击触发器后,我的 div 会立即扩展,而不是随着时间的推移发生...这是为什么,我该如何解决?
html
<div class="card" #panel [ngClass]="{heightChange: panel.isExpanded}">
<div class="header">
<div class="itemName">Some text goes here</div>
<mat-icon *ngIf="!panel.isExpanded" (click)="panel.isExpanded=true">edit</mat-icon>
<mat-icon *ngIf="panel.isExpanded" (click)="panel.isExpanded=false">cancel</mat-icon>
</div>
</div>
css
div.card {
background: white;
padding: 12px;
justify-items: center;
transition: all 0.5s;
}
mat-icon {
cursor: pointer;
}
div.header {
display: flex;
justify-content: space-between;
}
.heightChange {
height: 150px;
}
解决方案
只需height
为您的类添加一个属性以div.card
获得初始高度。
然后添加另一个以div.card.heightChange
新高度命名的类。transition
只为height
而不是全部。
将您的 CSS 类更改为:
div.card {
background: white;
padding: 12px;
height: 25px;
justify-items: center;
transition: height 0.5s;
}
div.card.heightChange {
height: 150px;
}
这是您参考的工作示例 StackBlitz。
推荐阅读
- c# - c# 使用 PostAsXmlAsync 需要将 content-type 更改为 text/xml
- php - 使用for循环循环时如何避免重复?
- c# - 需要帮助对 linux Docker 中的 .NET Core 2.1 API 进行故障排除
- android - android.content.res.Resources$NotFoundException 仅在棉花糖中出错,但在牛轧糖中正常工作
- python - 如果Windows上有两个相同版本的python,如何使用pip安装一个包
- angular - 如何在 Angular 中测试 form.valueChanges?
- javascript - React 组件记录对象,然后在同一对象上记录未定义
- javascript - 在从 Sybase 到 MongoDB 运行 ETL 时使用三元表达式
- insertion-sort - 我们可以写marks[j]=marks[i]; 在 while 循环内而不是标记[i+1]=marks[i];
- angular - 如何配置 Google App Engine yaml 文件以处理 404 错误